EFileTahi-A Posted August 8, 2004 Posted August 8, 2004 Hoe can i call a function? (call myPrivateSub) Oh my god! In VB6 this issues were so simple! (Is there realy need to complicate?) Quote
Administrators PlausiblyDamp Posted August 8, 2004 Administrators Posted August 8, 2004 Just use the function name and pass in any parameters it expects i.e. private void button1_Click(object sender, System.EventArgs e) { int j; j=Test(3); } //sample function private int Test(int i) { return 2 * i; } Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
EFileTahi-A Posted August 8, 2004 Author Posted August 8, 2004 Well, so, how can i trigger the button_click throught code? vb6 example: call button1_click Quote
Administrators PlausiblyDamp Posted August 8, 2004 Administrators Posted August 8, 2004 You could just call the function and pass in dummy arguments button1_Click(this, new System.EventArgs) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
EFileTahi-A Posted August 8, 2004 Author Posted August 8, 2004 public void DrawRectanglesRectangle(PaintEventArgs e) am trying to call the function how should i call it? DrawRectanglesRectangule(New PaintEventArgs) ???? Quote
Administrators PlausiblyDamp Posted August 8, 2004 Administrators Posted August 8, 2004 It kind of depends on what the DrawRectanglesRectangule actually does. PaintEventArgs are normally passed to a forms Paint Event - it allows you to get to the graphics object and also identify what region needs repainting. Without knowing more about the code in question and what it does (or who wrote it) then it's very difficult to say what to pass in as a parameter. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
EFileTahi-A Posted August 8, 2004 Author Posted August 8, 2004 public void DrawRectanglesRectangle(PaintEventArgs e) { // Create pen. Pen blackPen = new Pen(Color.Black, 3); // Create array of rectangles. Rectangle[] rects = { new Rectangle( 0, 0, 100, 200), new Rectangle(100, 200, 250, 50), new Rectangle(300, 0, 50, 100) }; // Draw rectangles to screen. e.Graphics.DrawRectangles(blackPen, rects); } here is the code Quote
Administrators PlausiblyDamp Posted August 8, 2004 Administrators Posted August 8, 2004 Where is this code being called from? If from the Paint event then just use DrawRectanglesRectangle(e); Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
EFileTahi-A Posted August 8, 2004 Author Posted August 8, 2004 i want to call it when I press a button or throught the Load_form... Quote
Joe Mamma Posted August 8, 2004 Posted August 8, 2004 Rectangle[] GetFormRectangles() { return new Rectangle[] { new Rectangle( 0, 0, 100, 200), new Rectangle(100, 200, 250, 50), new Rectangle(300, 0, 50, 100) }; } private void DrawFormRectanglesOnGraphics(Graphics g) { g.DrawRectangles(new Pen(Color.Black, 3), GetFormRectangles()); } public void DrawRectanglesOnControl(Control ctrl) { DrawRectanglesOnGraphics(ctrl.CreateGraphics()); } private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { DrawRectanglesOnGraphics(e.Graphics); } private void button1_Click(object sender, System.EventArgs e) { DrawRectanglesOnControl(this); } you could also just force the entre form to repaint private void button1_Click(object sender, System.EventArgs e) { this.Refresh(); } Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Joe Mamma Posted August 8, 2004 Posted August 8, 2004 Here to serve. Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.