473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how can i draw a rectangle from another winform?

7
i made 3 forms . 1.. frmMain(it is the mdiContainer) (form)
2........frmEditable (form)
3....... frmTools (form)
now
i just want that when i click on the rectangle button from frmTools form a rectangle must should be drawn on frmEditable form.
Sep 9 '08 #1
6 1587
cloud255
427 Expert 256MB
Hi there,

well if you create an event in the form with the controls which passes a value of some sort (an enumeration based on the selected shape) and subscibe to that event in the form where you want to draw the shape, you can have a switch to based on the eventargs.

then its simply calling the right procedure to draw the right shape.

Good luck
Sep 9 '08 #2
maifs
7
dear knew that but how it is..
where can i call it. draw is a function and i have to take result in frmEditable (form) .can you say that i should call it on some controls?
if yes then how?
there is a huge confusion about this in my mind ..
kindly explain me with some code...
thx
Sep 9 '08 #3
cloud255
427 Expert 256MB
first create the event:

Expand|Select|Wrap|Line Numbers
  1. event eventhandler<ToolTypeArgs> toolChanged;
when you raise the event:

Expand|Select|Wrap|Line Numbers
  1. if(this.toolChanged != null)
  2. {
  3.   this.toolChanged(this, new ToolTypeArgs(ToolTypes.Rectangle));
  4. }
thats how to create an event with custom arguments, you need to first create the ToolTypeArgs class, it must inherit from EventArgs and I used a ToolTypes enumeration which you will need to create.

try this, subscribe to the event in the form where you will draw, use a switch in the eventHandler to call the correct draw procedure (or even better create overridden draw functions). Try this and if you still have problems, post the code with which you are struggling.
Sep 9 '08 #4
maifs
7
i m sending this..

Expand|Select|Wrap|Line Numbers
  1. namespace I_M_Editor
  2. {
  3.     public partial class frmMain : Form
  4.     {
  5.         Bitmap m = new Bitmap(2, 2);
  6.         double Zoom = 1.0f;
  7.       //  PictureBox pictureBox1=null;
  8.  
  9.             IDrawableImages img = null;
  10.  //           IDrawableShapes shp= null; 
  11.  
  12.  
  13.         public frmMain()
  14.         {
  15.             InitializeComponent();
  16.             img = new Images();           
  17.  
  18.         }
  19.  
  20.         private void frmMain_Load(object sender, EventArgs e)
  21.         {
  22.             frmToolBox frm = new frmToolBox();
  23.             frm.MdiParent = this;
  24.             frm.Show();
  25.             frmEditable frm2 = new frmEditable();
  26.             frm2.MdiParent = this;
  27.             frm2.Show();
  28.  
  29.  
  30.         }
  31.  
  32.  
  33.  
  34.         protected override void OnPaint(PaintEventArgs e)
  35.         {
  36.  
  37.  
  38.         }
  39.  
  40.         private void tsxOptionOpen_Click(object sender, EventArgs e)
  41.         {
  42.             OpenFileDialog openFileDialog = new OpenFileDialog();
  43.  
  44.             openFileDialog.InitialDirectory = "c:\\";
  45.             openFileDialog.Filter = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg|All valid files (*.bmp/*.jpg)|*.bmp/*.jpg";
  46.             openFileDialog.FilterIndex = 2;
  47.             openFileDialog.RestoreDirectory = true;
  48.  
  49.             if (DialogResult.OK == openFileDialog.ShowDialog())
  50.             {
  51.               m = (Bitmap)Bitmap.FromFile(openFileDialog.FileName);
  52.         }
  53.  
  54.  
  55.         }    
  56.  
  57.         public void Rect()
  58.         {
  59.             Graphics g = this.CreateGraphics();
  60.             Pen p = new Pen(Color.Red);
  61.             g.DrawRectangle(p, 260, 260, 100, 100);
  62.  
  63.         }
  64.  
  65.     }
  66. }
  67.  
  68.  
  69.  
  70. namespace I_M_Editor
  71. {
  72.     public partial class frmEditable : Form
  73.     {
  74.         public frmEditable()
  75.         {
  76.             InitializeComponent();
  77.  
  78.         }
  79.  
  80.         private void frmEditable_Load(object sender, EventArgs e)
  81.         {
  82.  
  83.         }
  84.  
  85.     }
  86. }
  87.  
  88.  
  89. namespace I_M_Editor
  90. {
  91.     public partial class frmToolBox : Form
  92.     {
  93.         public frmToolBox()
  94.         {
  95.             InitializeComponent();
  96.         }
  97.  
  98.         private void lblRect_Click(object sender, EventArgs e)
  99.         {
  100.             ((frmMain)this.MdiParent).Rect();      
  101.  
  102.  
  103.  
  104.  
  105.         }
  106.  
  107.  
  108.     }
  109.  

i want to draw it in frmEditable(form).
frmTools(form) contain tools from which i click lblRect (its a label)
,a rectangle should be drawn on frmEditable('s form).
Sep 9 '08 #5
cloud255
427 Expert 256MB
ok, i gave a suggestion to use a custom event. I dont see you trying that anywhere, you dont use code tags and post REALLY quickly after i post. I take the time to think about your problem, please take the time to think about my post and try to use my advice or post 'no thank you' and i will stop. I'm not gonna write this project for you.

Best of luck to you
Sep 9 '08 #6
maifs
7
dear i m not asking you to write my whole project..
dear my project is not a short project.
its just starting...

ok..
Sep 9 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint...
1
by: Praveen | last post by:
Hello, I have a web page which will display the map of a city/place. I have a toolbar which contains 'zoom in' and 'zoom out' buttons. When the user clicks on zoom in/zoom out button, he should...
3
by: Colin McGuire | last post by:
Hi there. I have written a small procedure to draw various shapes on things. A bit of it is shown below. Private Sub drawShape(ByVal shapeType As Integer, ByRef g As Graphics) Select Case...
1
by: Rob Richardson | last post by:
Greetings! I am creating a form that will contain information that will eventually be on a label. The label has a 2-column table with lines separating the cells. I want my form to resemble the...
3
by: Tom | last post by:
Hi Hi i am trying to draw on top of a button on a standard toolbar. All i want to do is draw a small rectangle on the button to represent the selected color. I have tried the folowing code in...
7
by: Mark Ingram | last post by:
Hi, how can i draw a rounded rectange, with a border within a specified area? i.e. if i have a Rectangle with width and height of 100, how can i draw a rectange with 2 pixel border inside of the...
1
by: Jeff Waskiewicz | last post by:
Hello All, I'm trying to solve a nagging problem. The goal is to draw a rectangle over the top of all the other controls on a form. Specifically, over a ChartFX control. The user would draw...
10
by: Phil | last post by:
I would like to draw some text which will be in front of any other controls, but without obscuring them completely. If I use DrawString in the form's Paint handler the text is always behind, not in...
1
by: kummu4help | last post by:
hi, i want to draw rectangle based on mousedrag event. if user dragging the mouse, then the rectangle on the applet should increase or decrease basing on current mouse coordinates. i have the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.