Click here to Skip to main content
15,907,392 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Help with VB 2008.NET, Please Pin
Tom Deketelaere10-Dec-09 23:42
professionalTom Deketelaere10-Dec-09 23:42 
GeneralRe: Help with VB 2008.NET, Please Pin
treashunter10-Dec-09 23:49
treashunter10-Dec-09 23:49 
GeneralRe: Help with VB 2008.NET, Please Pin
Tom Deketelaere10-Dec-09 23:57
professionalTom Deketelaere10-Dec-09 23:57 
GeneralRe: Help with VB 2008.NET, Please PinPopular
treashunter11-Dec-09 0:06
treashunter11-Dec-09 0:06 
GeneralRe: Help with VB 2008.NET, Please Pin
dan!sh 11-Dec-09 0:11
professional dan!sh 11-Dec-09 0:11 
GeneralRe: Help with VB 2008.NET, Please Pin
The Man from U.N.C.L.E.11-Dec-09 23:06
The Man from U.N.C.L.E.11-Dec-09 23:06 
GeneralRe: Help with VB 2008.NET, Please Pin
Paul Conrad12-Dec-09 4:56
professionalPaul Conrad12-Dec-09 4:56 
GeneralRe: Help with VB 2008.NET, Please Pin
Johan Hakkesteegt11-Dec-09 2:37
Johan Hakkesteegt11-Dec-09 2:37 
treashunter wrote:
Public Sub drawonform(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Call Button2_Click(sender, e)


Okay, this is the main problem. The paint event (especially of the form) can happen many times per second even, and is an uncontrolled (by you) event. That means it will happen whether you want to or not.
So in your code, as is, the code in your button click event will be executed just as many times (whether you want to or not).

In other words, do not use the Paint event, but rather the Form's Load event, or if absolutely necessary, VisibleChanged, in which case you need to check whether the form is being hidden or made visible.

And a good opportunity to practice good coding techniques:
As a rule of thumb, do not call an event from within other events just to run the code inside that event. Rather create a separate sub and move the code in the event to it. So in your case:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonpic.Click
  OpenPictureDialog()
End Sub

Public Sub drawonform(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
  OpenPictureDialog()
End Sub

Private Sub OpenPictureDialog()
  Try
    If (Form1.openDiag.ShowDialog() = Windows.Forms.DialogResult.OK) Then
      user = Form1.openDiag.FileName
    End If
  Catch ex as Exception
    MsgBox(ex.ToString)
  End Try
End Sub


My advice is free, and you may get what you paid for.

AnswerRe: Help with VB 2008.NET, Please Pin
Paul Conrad12-Dec-09 4:59
professionalPaul Conrad12-Dec-09 4:59 
QuestionHow to check Internet connection Pin
Tufail Ahmad10-Dec-09 18:28
Tufail Ahmad10-Dec-09 18:28 
AnswerRe: How to check Internet connection Pin
Eddy Vluggen11-Dec-09 2:13
professionalEddy Vluggen11-Dec-09 2:13 
GeneralRe: How to check Internet connection Pin
Tufail Ahmad11-Dec-09 19:00
Tufail Ahmad11-Dec-09 19:00 
GeneralRe: How to check Internet connection Pin
The Man from U.N.C.L.E.11-Dec-09 23:09
The Man from U.N.C.L.E.11-Dec-09 23:09 
AnswerRe: How to check Internet connection Pin
εїзεїзεїз12-Dec-09 0:32
εїзεїзεїз12-Dec-09 0:32 
AnswerRe: How to check Internet connection Pin
Paul Conrad12-Dec-09 5:00
professionalPaul Conrad12-Dec-09 5:00 
QuestionWorking with numbers???? Pin
A-dogg200910-Dec-09 17:49
A-dogg200910-Dec-09 17:49 
AnswerRe: Working with numbers???? Pin
Ashfield10-Dec-09 21:08
Ashfield10-Dec-09 21:08 
GeneralRe: Working with numbers???? Pin
A-dogg200916-Dec-09 17:34
A-dogg200916-Dec-09 17:34 
QuestionLocal machine problem with SQL DMO !!! Pin
cotdot1111110-Dec-09 13:27
cotdot1111110-Dec-09 13:27 
AnswerRe: Local machine problem with SQL DMO !!! Pin
Luc Pattyn10-Dec-09 14:14
sitebuilderLuc Pattyn10-Dec-09 14:14 
AnswerRe: Local machine problem with SQL DMO !!! Pin
Eddy Vluggen11-Dec-09 2:20
professionalEddy Vluggen11-Dec-09 2:20 
QuestionDataGridView in VB.NET.The empty row in the end!!! Pin
tannghia10-Dec-09 11:58
tannghia10-Dec-09 11:58 
AnswerRe: DataGridView in VB.NET.The empty row in the end!!! Pin
Andy_L_J12-Dec-09 9:05
Andy_L_J12-Dec-09 9:05 
Questionfreehand draw problem Pin
O.G.I.10-Dec-09 10:19
O.G.I.10-Dec-09 10:19 
QuestionSOAP/VB6 Reading Arrays Pin
ffowler10-Dec-09 5:37
ffowler10-Dec-09 5:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.