|
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.
|
|
|
|
|
As others have mentioned, do not have this type of operation inside a procedure that handles the Paint event as Paint event does happen often and you cannot control when it is triggered or not. From what I read of your description of what you are trying to achieve, you should be putting the code to open your open dialog in a button click event procedure for the button in question.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
In vb6.0, how can i check Internet connection. that is. Is net connected or not.
Send source code please
|
|
|
|
|
Tufail Ahmad wrote: Send source code please
Private Declare Function InternetGetConnectedState Lib "wininet.dll" _
(ByRef dwflags As Long, ByVal dwReserved As Long) As Long
Public Function IsOnline() As Boolean
Dim LFlags As Long
IsOnline = InternetGetConnectedState(LFlags, 0&)
End Function
I are Troll
|
|
|
|
|
IsOnline = InternetGetConnectedState(LFlags, 0&)
In the above line, LFlags returns some values, what does it mean.
Note: I am connected to Internet through LAN
|
|
|
|
|
|
Private Const FLAG_ICC_FORCE_CONNECTION = &H1
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Function Check_Internet_Connection() As Boolean
If InternetCheckConnection("http://www.google.com", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
Check_Internet_Connection = False
Else
Check_Internet_Connection = True
End If
End Function
Best Regards,
SOFTDEV
If you have knowledge, let others light their candles at it
|
|
|
|
|
Tufail Ahmad wrote: Send source code please
Sorry, it is not how this site works. People will offer help and hints as to what to do, but to just throw out code, no.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Hi eveyone,
I,m working on a program where I want to save numbers to a file and then be able to later have my program be able to tell me which numbers occur most often with in this file. I have managed to write to a text file and i even figured out how to read how many lines the file has. I,m stuck on retreiving the data. I,m using vsual basic 2008 by the way. Would it be better to use a database?? Thanks for any help you all can be.
Sincerely,
A-dogg
|
|
|
|
|
A-dogg2009 wrote: Would it be better to use a database
Depends on the volume of data and how much you want to manipulate it.
A-dogg2009 wrote: stuck on retreiving the data
Take a look at the SYSTEM.IO name space, filestreams
A-dogg2009 wrote: which numbers occur most often with in this file
Read up on LINQ, its perfect for this
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
|
Hi every one
I 'm using SQL DMO to connect database in my computer
But i can't connect to my database
Here my code:
Dim sever As New SQLDMO.SQLServer
sever.LoginSecure = True
sever.Connect("local")
how to connect to my local sever
I'm using SQLEXPRESS
thanks
|
|
|
|
|
this[^] contains the magic line you need to connect.
|
|
|
|
|
There's a walkthrough here; http://www.sqldbatips.com/showarticle.asp?ID=34.
Your server-instance is probably named "(local)\SQLEXPRESS"
I are Troll
|
|
|
|
|
Please help me to answer the following question! Thanks!
1.In VB.NET, when datasource of datagridview = datatable(Datatable contains data).On the datagridview display a grid of data ,the end row is empty.
What type of value of the cells on this row in VB.NET?How to check ?
2.Can I make the end row disappear?
|
|
|
|
|
2. Set:
DataGridView1.AllowUSerToAddRows = False
and
DataGridView1.AllowUserToDeleteRows = False
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
Hi,
I'm currently having a big problem with freehand drawing.
I want to do the following thing: I want to draw 2 freehand lines both with different colors and I need the final line to be on the top of the other lines created before. To store the lines I use 2 GraphicsPath objects, one GraphicsPath per color.
I tried to solve this problem by using two arrays like this:
Public MousePath0() As System.Drawing.Drawing2D.GraphicsPath
Public MousePath1() As System.Drawing.Drawing2D.GraphicsPath
My idea was to make a system which will remember the order of all lines and draw them correctly, but when I add an graphics path to the array and when I try to add line to this graphics path VB 2008 gives me an error "Object reference not set to an instance of an object."
Please help, I don't want to use exactly a GraphicsPath for the lines, it can be something different.
Thank you!
|
|
|
|
|
Hello All,
I am hoping someone could steer me in the right direction with a problem I am having.
I created a small app that sucessfully consumes a Web Service and traps the response. I am able to read individual pieces of the document but when it comes to arrays, I am having the most difficult time.
Below I have posted the XML response and what I am looking to store is the values in ref1 and ref2. But I don't know how to get at them. I see a reference to these 2 elements in the SearchServiceNames and ServiceLastModificationDates tags but I am totally lost on how to read and hook the two up.
Any help would be most appreciated. I thank you for your time and comments.
<?xml version="1.0"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns1:GetSearchServicesResponse SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://www.dwdev.com/Webservices/Freezerworks/">
<SearchServicesCount>3</SearchServicesCount>
<SearchServiceNames href="#ref-1"/>
<SearchServiceLastModificationDates href="#ref-2"/>
</ns1:GetSearchServicesResponse>
<SOAP-ENC:Array SOAP-ENC:arrayType="xsd:string[3]" id="ref-1">
<item>GetIDs</item>
<item>russtest</item>
<item>russtestservice</item>
</SOAP-ENC:Array>
<SOAP-ENC:Array SOAP-ENC:arrayType="xsd:date[3]" id="ref-2">
<item>2009-11-17</item>
<item>2009-11-16</item>
<item>2009-11-16</item>
</SOAP-ENC:Array></SOAP-ENV:Body>
</SOAP-ENV:Envelope>
|
|
|
|
|
Hello To All,
In My application i have provide the facility to Use directoly when Computer is log in. So i add the application to Startup in Registry. So my application is blocked by antivirus.
But Other application which are in Startup are not Blocked By Antivirus.
so please help me for How to Secure my application to Antivirus. And Give me the reason for that why antivirus not detecting those applications which are Add in Startup.
If you can think then I Can.
modified on Thursday, December 10, 2009 11:18 PM
|
|
|
|
|
Add an exception to your antivirus for your application.
See how generic of an answer that was? See how it's frustrating?
It's the same thing for me with your generic question.
|
|
|
|
|
Excellent.
|
|
|
|
|
Ok, here is the question
I have an array with let's say, the following values :
17
18
0
0
24
23
0
20
0
0
0
16
I need to approximate(average) the ZERO values to the non zero values.For example i would expect the 0 between the 23 and the 20, to become 21.5.
Or the first 2 zeros to be 20 and 22.
Can you help ?
It should be easy but i am completely stuck in here.
|
|
|
|
|
Johnkokk wrote: It should be easy but i am completely stuck in here.
This is simple mathematics. Add up the numbers surrounding the zeros and calculate the average (by division). Replace the zeros with the average values. Try doing it with pencil and paper to see how it can be achieved.
|
|
|
|
|
It's not really the average, though, if I've understood the question.
The sequence 23, 0, 20 becomes 23, 21.5, 20.
18, 0, 0, 24 becomes 18, 20, 22, 24
20, 0, 0, 0, 16 becomes 20, 19, 18, 17, 16.
Not sure what the technical term for that is. Interpolation? Even so, it is still simple maths. The only tricky bit is handling the end conditions if a 0 occurs at the first or last position in the array.
|
|
|
|
|
David Skelly wrote: It's not really the average, though, if I've understood the question.
You're right of course, I was confused (quite easy thing to do) by the questioner using the expression "approximate(average)".
|
|
|
|