|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
following code private void DrawShapesForm_Paint(object sender, PaintEventArgs e) { // references to object we will use Graphics graphicsObject = e.Graphics; // ellipse rectangle and gradient brush Rectangle drawArea1 = new Rectangle(5, 35, 30, 100); LinearGradientBrush linearBrush = new LinearGradientBrush(drawArea1, Color.Blue, Color.Yellow, LinearGradientMode.ForwardDiagonal); // draw ellipse filled with a blue-yellow gradient graphicsObject.FillEllipse(linearBrush, 5, 30, 65, 100); } //--------------------------------------- Now on a form I have placed a single command button and want the above to execute when I click it. In the (Paint) events tab of the button I have enabled DrawShapesForm_Paint. So far nothing is happening when I click the button. Am using VS2008. What am I doing wrong, or perhaps failing to do? TIA Mick Send the whole program (including Main) and I'll fix it
Show quoteHide quote "Michael" <mikh***@bigpond.com> schreef in bericht news:%23L$Q8pxYJHA.5108@TK2MSFTNGP05.phx.gbl... > Hello, I am trying to follow a graphics tutorial which gives the > following code > > private void DrawShapesForm_Paint(object sender, PaintEventArgs e) > { > // references to object we will use > Graphics graphicsObject = e.Graphics; > // ellipse rectangle and gradient brush > Rectangle drawArea1 = new Rectangle(5, 35, 30, 100); > LinearGradientBrush linearBrush = > new LinearGradientBrush(drawArea1, Color.Blue, > Color.Yellow, LinearGradientMode.ForwardDiagonal); > // draw ellipse filled with a blue-yellow gradient > graphicsObject.FillEllipse(linearBrush, 5, 30, 65, 100); > } > //--------------------------------------- > Now on a form I have placed a single command button and want the > above to execute when I click it. In the (Paint) events tab of the button > I have > enabled DrawShapesForm_Paint. > So far nothing is happening when I click the button. Am using VS2008. > What am I doing wrong, or perhaps failing to do? > TIA Mick >
Show quote
Hide quote
" Martijn Mulder" <i@m> wrote in message // Form1.Designer.csnews:494eb9bd$0$16079$dbd41001@news.wanadoo.nl... > Send the whole program (including Main) and I'll fix it > > > "Michael" <mikh***@bigpond.com> schreef in bericht > news:%23L$Q8pxYJHA.5108@TK2MSFTNGP05.phx.gbl... >> Hello, I am trying to follow a graphics tutorial which gives the >> following code >> >> private void DrawShapesForm_Paint(object sender, PaintEventArgs e) >> { >> // references to object we will use >> Graphics graphicsObject = e.Graphics; >> // ellipse rectangle and gradient brush >> Rectangle drawArea1 = new Rectangle(5, 35, 30, 100); >> LinearGradientBrush linearBrush = >> new LinearGradientBrush(drawArea1, Color.Blue, >> Color.Yellow, LinearGradientMode.ForwardDiagonal); >> // draw ellipse filled with a blue-yellow gradient >> graphicsObject.FillEllipse(linearBrush, 5, 30, 65, 100); >> } >> //--------------------------------------- >> Now on a form I have placed a single command button and want the >> above to execute when I click it. In the (Paint) events tab of the button >> I have >> enabled DrawShapesForm_Paint. >> So far nothing is happening when I click the button. Am using VS2008. >> What am I doing wrong, or perhaps failing to do? >> TIA Mick >> > > namespace WindowsFormsApplication4 { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #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 InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(305, 75); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; this.button1.Paint += new System.Windows.Forms.PaintEventHandler(this.DrawShapesForm_Paint); this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(410, 306); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1; } } // end Form1.Designer.cs // start Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace WindowsFormsApplication4 { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } } // end Program.cs //Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void DrawShapesForm_Paint(object sender, PaintEventArgs e) { // references to object we will use Graphics graphicsObject = e.Graphics; // ellipse rectangle and gradient brush Rectangle drawArea1 = new Rectangle(5, 35, 30, 100); LinearGradientBrush linearBrush = new LinearGradientBrush(drawArea1, Color.Blue, Color.Yellow, LinearGradientMode.ForwardDiagonal); // draw ellipse filled with a blue-yellow gradient graphicsObject.FillEllipse(linearBrush, 5, 30, 65, 100); } private void button1_Click(object sender, EventArgs e) { //No Code in here yet, I just want to call DrawShapesForm_Paint //drawing when clicked } } } // Thanks Martin for having a look...Mick
Show quote
Hide quote
"Michael" <mikh***@bigpond.com> schreef in bericht Here is the modified button1_Click method:news:OFbGOX8YJHA.6036@TK2MSFTNGP05.phx.gbl... > > " Martijn Mulder" <i@m> wrote in message > news:494eb9bd$0$16079$dbd41001@news.wanadoo.nl... >> Send the whole program (including Main) and I'll fix it >> >> >> "Michael" <mikh***@bigpond.com> schreef in bericht >> news:%23L$Q8pxYJHA.5108@TK2MSFTNGP05.phx.gbl... >>> Hello, I am trying to follow a graphics tutorial which gives the >>> following code >>> >>> private void DrawShapesForm_Paint(object sender, PaintEventArgs e) >>> { >>> // references to object we will use >>> Graphics graphicsObject = e.Graphics; >>> // ellipse rectangle and gradient brush >>> Rectangle drawArea1 = new Rectangle(5, 35, 30, 100); >>> LinearGradientBrush linearBrush = >>> new LinearGradientBrush(drawArea1, Color.Blue, >>> Color.Yellow, LinearGradientMode.ForwardDiagonal); >>> // draw ellipse filled with a blue-yellow gradient >>> graphicsObject.FillEllipse(linearBrush, 5, 30, 65, 100); >>> } >>> //--------------------------------------- >>> Now on a form I have placed a single command button and want the >>> above to execute when I click it. In the (Paint) events tab of the >>> button I have >>> enabled DrawShapesForm_Paint. >>> So far nothing is happening when I click the button. Am using VS2008. >>> What am I doing wrong, or perhaps failing to do? >>> TIA Mick >>> >> >> > // Form1.Designer.cs > namespace WindowsFormsApplication4 > { > partial class Form1 > { > /// <summary> > /// Required designer variable. > /// </summary> > private System.ComponentModel.IContainer components = null; > > /// <summary> > /// Clean up any resources being used. > /// </summary> > /// <param name="disposing">true if managed resources should be > disposed; otherwise, false.</param> > protected override void Dispose(bool disposing) > { > if (disposing && (components != null)) > { > components.Dispose(); > } > base.Dispose(disposing); > } > > #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 InitializeComponent() > { > this.button1 = new System.Windows.Forms.Button(); > this.SuspendLayout(); > // > // button1 > // > this.button1.Location = new System.Drawing.Point(305, 75); > this.button1.Name = "button1"; > this.button1.Size = new System.Drawing.Size(75, 23); > this.button1.TabIndex = 0; > this.button1.Text = "button1"; > this.button1.UseVisualStyleBackColor = true; > this.button1.Paint += new > System.Windows.Forms.PaintEventHandler(this.DrawShapesForm_Paint); > this.button1.Click += new > System.EventHandler(this.button1_Click); > // > // Form1 > // > this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); > this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; > this.ClientSize = new System.Drawing.Size(410, 306); > this.Controls.Add(this.button1); > this.Name = "Form1"; > this.Text = "Form1"; > this.ResumeLayout(false); > > } > > #endregion > > private System.Windows.Forms.Button button1; > } > } > > // end Form1.Designer.cs > > // start Program.cs > using System; > using System.Collections.Generic; > using System.Linq; > using System.Windows.Forms; > > > namespace WindowsFormsApplication4 > { > static class Program > { > /// <summary> > /// The main entry point for the application. > /// </summary> > [STAThread] > static void Main() > { > Application.EnableVisualStyles(); > Application.SetCompatibleTextRenderingDefault(false); > Application.Run(new Form1()); > } > } > } > > // end Program.cs > > //Form1.cs > > using System; > using System.Collections.Generic; > using System.ComponentModel; > using System.Data; > using System.Drawing; > using System.Drawing.Drawing2D; > using System.Linq; > using System.Text; > using System.Windows.Forms; > > namespace WindowsFormsApplication4 > { > public partial class Form1 : Form > { > public Form1() > { > InitializeComponent(); > } > > private void DrawShapesForm_Paint(object sender, PaintEventArgs e) > { > // references to object we will use > Graphics graphicsObject = e.Graphics; > // ellipse rectangle and gradient brush > Rectangle drawArea1 = new Rectangle(5, 35, 30, 100); > LinearGradientBrush linearBrush = > new LinearGradientBrush(drawArea1, Color.Blue, > Color.Yellow, LinearGradientMode.ForwardDiagonal); > > // draw ellipse filled with a blue-yellow gradient > graphicsObject.FillEllipse(linearBrush, 5, 30, 65, 100); > > > > } > > private void button1_Click(object sender, EventArgs e) > { > //No Code in here yet, I just want to call DrawShapesForm_Paint > //drawing when clicked > } > } > } > > // Thanks Martin for having a look...Mick > > > private void button1_Click(object sender, EventArgs e) { this.Paint += new System.Windows.Forms.PaintEventHandler(DrawShapesForm_Paint); Invalidate(); } |
|||||||||||||||||||||||