Control Drawing Issue

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have created a transparent control and I am using to to create drawing objects Inside the transparent objects I have created I am trying to using the draw shapes oval, rectangle etc. An example would be like in word are when you drag an oval onto the screen, the drawing resizes as the control does. The problem I am running into is actually drawing the rectangle. I am attempting to use this code here:

Rect = new Rectangle(this.Bounds.X - 10, (this.Bounds.Y -10), (this.Bounds.Width - 10), (this.Bounds.Height - 10))

I have placed this code in the Resize event. It does draw, however it seems to be reponsive to the bounds of it's container rather then the control itself. What I could like is if someone can help me figure out how to draw a rectangle close to the edges of the custom control and the drawing would resize itself as the control does. Please help!!! If anyone has any examples please email them (e-mail address removed)
 
Hi Mike,
How do you create your transparent control. I've just tried one and it
returns me the right value for its bounding rectangle. Here is the code of
my transparent control.
This is the code you usually can find as a solution of "how to create a
control that supports transparent color as a background color". However, I
believe the control should have its WS_EX_TRANSPARENT style set as well.


====
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace TransparentCtrl
{
/// <summary>
/// Summary description for TranspCtrl.
/// </summary>
public class TranspCtrl : System.Windows.Forms.UserControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public TranspCtrl()
{

SetStyle(ControlStyles.SupportsTransparentBackColor|ControlStyles.ResizeRedr
aw, true);
InitializeComponent();
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// TranspCtrl
//
this.BackColor = System.Drawing.SystemColors.Control;
this.Name = "TranspCtrl";

}
#endregion

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
e.Graphics.DrawRectangle(Pens.Fuchsia,
Rectangle.Inflate(Bounds, -5, -5));
}


}
}
====
--
HTH
B\rgds
100

Mike Starkey said:
I have created a transparent control and I am using to to create drawing
objects Inside the transparent objects I have created I am trying to using
the draw shapes oval, rectangle etc. An example would be like in word are
when you drag an oval onto the screen, the drawing resizes as the control
does. The problem I am running into is actually drawing the rectangle. I
am attempting to use this code here:
Rect = new Rectangle(this.Bounds.X - 10, (this.Bounds.Y -10),
(this.Bounds.Width - 10), (this.Bounds.Height - 10));
I have placed this code in the Resize event. It does draw, however it
seems to be reponsive to the bounds of it's container rather then the
control itself. What I could like is if someone can help me figure out how
to draw a rectangle close to the edges of the custom control and the drawing
would resize itself as the control does. Please help!!! If anyone has any
examples please email them (e-mail address removed)
 
Back
Top