very simple program to draw a filled rectangle .. why it does not work ?

时间:2015-05-08 09:58:08

标签: c# windows forms

I am new with using graphics and I am trying to draw a filled rectangle when the form opens.. but nothing is working and do not know the reason

here is my code :

Generic Heart rate Sensor

where Result is my form that is supposed I draw the rectangle on when it is loaded

but when I load the form nothing happens at all

where the problem ?

thanks in advance

1 个答案:

答案 0 :(得分:2)

Add handler to + event in form's constructor:

(function () {

    var debug = false

    if (debug === false) {
        if ( typeof(window.console) === 'undefined') { window.console = {}; }
        window.console.log = function () {};
    }
})()

And create method frmMain_Paint:

Paint

Tips

  1. Use e.Graphics to draw (not /// <summary> /// form constructor /// </summary> public frmMain() { InitializeComponent(); this.Paint += frmMain_Paint; } )
  2. Use void frmMain_Paint(object sender, PaintEventArgs e) { using (System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Green)) { e.Graphics.FillRectangle(myBrush, new Rectangle(0, 0, 200, 300)); } } keyword as in example above.