473,769 Members | 5,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Launching C# Graphics Drawing from Menu

1 New Member
Hi ..
Just getting interested to learn C# and needs help.

I want to write C# application so that the program will execute and draw graphics when the user select the drawing menu from the main menu, SigDraw.

Here is the codes:-

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Drawing. Drawing2D;

namespace myDraw
{
/// <summary>
/// Summary description for WinForm.
/// </summary>
public class WinForm : System.Windows. Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;
private System.Windows. Forms.MainMenu mainMenu1;
private System.Windows. Forms.MenuItem menuItem1;
private System.Windows. Forms.MenuItem menuItem2;
private System.Windows. Forms.MenuItem menuItem3;
private System.Windows. Forms.MenuItem menuItem4;

public WinForm()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent call
//
this.Text = "Illustrati ng DrawXXX() methods";
this.Size = new Size(450,400);
this.Paint += new PaintEventHandl er(Draw_Graphic s);

}

public void Draw_Graphics(o bject sender,PaintEve ntArgs e) {
/* Graphics g = e.Graphics;
Pen penline = new Pen(Color.Red,5 );
Pen penellipse = new Pen(Color.Blue, 5);
Pen penpie = new Pen(Color.Tomat o,3);
Pen penpolygon = new Pen(Color.Maroo n,4);
*/
/*DashStyle Enumeration values are Dash,
DashDot, DashDotDot, Dot, Solid, etc*/
/*
penline.DashSty le = DashStyle.Dash;
g.DrawLine(penl ine,50,50,100,2 00);

//Draws an Ellipse
penellipse.Dash Style = DashStyle.DashD otDot;
g.DrawEllipse(p enellipse,15,15 ,50,50);

//Draws a Pie
penpie.DashStyl e = DashStyle.Dot;
g.DrawPie(penpi e,90,80,140,40, 120,100);

//Draws a Polygon
g.DrawPolygon(p enpolygon,new Point[]{
new Point(30,140),
new Point(270,250),
new Point(110,240),
new Point(200,170),
new Point(70,350),
new Point(50,200)}) ;
*/
}


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

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.mainMenu1 = new System.Windows. Forms.MainMenu( );
this.menuItem1 = new System.Windows. Forms.MenuItem( );
this.menuItem4 = new System.Windows. Forms.MenuItem( );
this.menuItem2 = new System.Windows. Forms.MenuItem( );
this.menuItem3 = new System.Windows. Forms.MenuItem( );
//
// mainMenu1
//
this.mainMenu1. MenuItems.AddRa nge(new System.Windows. Forms.MenuItem[] {
this.menuItem1,
this.menuItem2} );
//
// menuItem1
//
this.menuItem1. Index = 0;
this.menuItem1. MenuItems.AddRa nge(new System.Windows. Forms.MenuItem[] {
this.menuItem4} );
this.menuItem1. Text = "&File";
//
// menuItem4
//
this.menuItem4. Index = 0;
this.menuItem4. Text = "E&xit";
this.menuItem4. Click += new System.EventHan dler(this.menuI tem4_Click);
//
// menuItem2
//
this.menuItem2. Index = 1;
this.menuItem2. MenuItems.AddRa nge(new System.Windows. Forms.MenuItem[] {
this.menuItem3} );
this.menuItem2. Text = "&Draw";
//
// menuItem3
//
this.menuItem3. Index = 0;
this.menuItem3. Text = "&SigDraw";
this.menuItem3. Click += new System.Drawing. Graphics(this.m enuItem3_Click) ;
//
// WinForm
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 268);
this.Menu = this.mainMenu1;
this.Name = "WinForm";
this.Text = "WinForm";
}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new WinForm());
}

private void menuItem4_Click (object sender, System.EventArg s e)
{
Application.Exi t();
}

private void Draw_myGraphics (object sender, PaintEventArgs e)
//menuItem3_Click (object sender, System.EventArg s e)
{
Graphics g = e.Graphics;
Pen penline = new Pen(Color.Red,5 );
Pen penellipse = new Pen(Color.Blue, 5);
Pen penpie = new Pen(Color.Tomat o,3);
Pen penpolygon = new Pen(Color.Maroo n,4);


/*DashStyle Enumeration values are Dash,
DashDot, DashDotDot, Dot, Solid, etc*/

penline.DashSty le = DashStyle.Dash;
g.DrawLine(penl ine,50,50,100,2 00);

//Draws an Ellipse
penellipse.Dash Style = DashStyle.DashD otDot;
g.DrawEllipse(p enellipse,15,15 ,50,50);

//Draws a Pie
penpie.DashStyl e = DashStyle.Dot;
g.DrawPie(penpi e,90,80,140,40, 120,100);

//Draws a Polygon
g.DrawPolygon(p enpolygon,new Point[]{
new Point(30,140),
new Point(270,250),
new Point(110,240),
new Point(200,170),
new Point(70,350),
new Point(50,200)}) ;

}

private void menuItem3_Click (object sender, System.Drawing. Graphics e)
{
Graphics g = e.Graphics;

}
}
}

The Problem : The graphic is drawn eventhough the user has not selected menuItem3, 'SigDraw'

Appreciate you helps.

Thanks
Hasim AH, Sept. 21st. 2006
Sep 21 '06 #1
0 3557

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

Similar topics

12
2387
by: Sanjay | last post by:
hi, We are currently porting our project from VB6 to VB .NET. Earlier we used to make scale transformations on objects like pictureBox , forms etc.Now Such transformations are made on the graphics object of the form/pictureBox. Should It be better if make a graphics object from my pictureBox in load event handler of the form and store it as member variable of the form , make
1
9577
by: Paul Hoad | last post by:
I'm trying to use MeasureString() to determine the length in pixels of a string However to do I need a System.Drawing.Graphics object to do this I need to create a System.Drawing.Graphics object for which there is only two constructors System.Drawing.Graphics.FromHdc
1
3235
by: Hadar | last post by:
Hi, I'm getting "object is currently in use elsewhere" when I use System.Drawing.Graphics.MesureString. This is what I do: My controls use a utility class the helps it to mesure strings. To get the best performance for the utility class, its members, as well as the System.Drawing.Graphics object, are static:
3
2763
by: Bob Steuernagel | last post by:
This code is for a simple drawing program that lets the user draw lines, rectangles, and circles in different colors. When the menu is dropped down to change objects, it erases anything drawn underneath the menu drop-down area. What is wrong? Imports System.Drawing Public Class Form1 Inherits System.Windows.Forms.Form
8
3328
by: Nathan Sokalski | last post by:
I am trying to write code to rotate a graphic that I have. Here is the code I am currently using: Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("images/frog.gif"))) Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) froggraphic.RotateTransform(90) frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
6
3245
by: Chris Dunaway | last post by:
The method for printing documents in .Net can be confusing, especially for newer users. I would like to create a way to simplify this process. My idea would be implemented using a PrintDocument (much like the current model), but my PrintDocument would have a Pages collection such that each time you need to have an additional page, you would just add another page to the collection and then use the page object for the actual drawing etc. ...
2
1548
by: jediknight | last post by:
Hi, I am designing a web form which as an imagemap. I need to obtain a graphics object so I can draw on this imagemap. Can anyone tell me how to do this? I have tried creating a bitmap object and doing Graphics.FromImage call but the image on the imagemap disappears leaving a black background.
11
6732
by: Slickuser | last post by:
I have this function that will fill the ellipse every 10 seconds with specific x,y,w,h. Now I want do the the reverse, to clear the ellipse with given x,y using Timer at every 30s. Or I have put these (x,y,w,h) to an array? Later go back the array and fill ellipse with the same color as background? Is there an easy way?
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9863
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7408
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.