|
It may be best to just create a custom control so that you can manage all the drawing so that it is exactly what you want. The picturebox control is basically only used for displaying pictures and not much else, but a custom control can do what you want and more.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
Hello,
You can try the given code.
BEGIN CODE
<br />
Dim MD, MU As Point<br />
<br />
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown<br />
<br />
MD = e.Location<br />
<br />
End Sub<br />
<br />
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove<br />
<br />
If e.Button = Windows.Forms.MouseButtons.Left Then<br />
<br />
MU = e.Location<br />
DrawLine()<br />
End If<br />
<br />
End Sub<br />
<br />
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp<br />
<br />
MU = e.Location<br />
DrawLine()<br />
<br />
End Sub<br />
<br />
Public Sub DrawLine()<br />
<br />
Dim g As Graphics<br />
g = Me.PictureBox1.CreateGraphics<br />
g.Clear(Me.PictureBox1.BackColor)<br />
g.DrawLine(Pens.Blue, MD, MU)<br />
g.Dispose()<br />
<br />
End Sub<br />
I hope this will help.
Regards,
Allen Smith
ComponentOne LLC
www.componentone.com
|
|
|
|
|
hy thnx Allen, your code works fine . but i also want to draw a rectangle on picture box and for this i need to know the quardinate of mouse down and up position. I also want to use freehand drawer, i dont have any idea abt it. Thanks for the solution again.
Fareed
|
|
|
|
|
I am trying to draw rectangle but it is drawn just with a single click (with different lengths and widths) also it is going out of pictureBox area But i want it to start from where mouse key is pressed and end where mouse key is released. i think there is something wrong with my quardinate. Waiting for reply.
Thanks
[code]
Dim x1, y1, x2, y2 As Integer
Dim MD, MU As Point
Dim mywidth As Integer
Dim drawtool As String
Dim drawpen As Pen
Dim g As Graphics
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
MD = e.Location
x1 = MD.X
y1 = MD.Y
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
If e.Button = Windows.Forms.MouseButtons.Left Then
MU = e.Location
x2 = MD.X
y2 = MD.Y
DrawRectangle()
End Sub
Public Sub DrawRectangle()
gr = PictureBox1.CreateGraphics
Dim solidColorBrush As SolidBrush = New SolidBrush(Color.Red)
Dim coloredPen As Pen = New Pen(solidColorBrush)
coloredPen.Width = 3
coloredPen.Color = Color.Blue
Dim drawArea2 As Rectangle = New Rectangle(x1, y1, x2, y2)
gr.DrawRectangle(coloredPen, drawArea2)
gr.Dispose()
End Sub
[End code]
|
|
|
|
|
hello everyone.
i want to open website by using vb6.0 application.
Please help..
Shazz here to help you...
|
|
|
|
|
|
And including clear punctuation.
Lloyd J. Atkinson
"Logic will get you from A to B, but imagination will take you everywhere" - ALbert Einstein
I look at Microsoft, and turn to my poster on the wall saying: "Bang head here in case of stress".
|
|
|
|
|
Hi everyone,
I'm writing a Windows Forms application that shows movies, images, scrolling text, ... in different panels on a form.
This is the process that I do:
1) I create the different panels on the form
2) I create an object of another class (MyClass), set some properties and call the start method of the created object.
3) The start method creates an instance of a control to show the movie, image, scrolling text, ... and add this instance to the right panel.
--> Step 2 and 3 happens for each panel on the form.
I encounter one problem when I use this process. I see that the scrolling text waits for a short moment when the movie starts to load, after it is loaded the text is running again. I thought that I could fix this problem by using threads.
So I changed my process:
1) I create the different panels on the form (MainThread)
2) I create an object of MyClass and set the property where the movie, image,... has to run in (so in which panel)
3) I create a new thread (MyNewThread). When the thread starts, I execute the start method in the MyClass object. This start method makes a new instance of a control. To add my instance of the control to the panel, I have to invoke my panel. Which results that I'm back in the MainThread. So the control, plays again in the MainThread.
So this process don't solve the problem about my scrolling text.
I want that the controls are running in a different thread than the MainThread. But I think this is not possible, because the main form is running in the MainThread and everything that I want to add on the form has to be done in the MainThread by using the invoke. I'm right?
The only thing that I want is that the instance of a control in a panel is working on his own. So that loading some things in one control does not have an influence on another control.
Has someone any idea to do it?
Thanks in advance,
Kurt.
|
|
|
|
|
Move your scrolling text to its own control that, itself, is threaded.
|
|
|
|
|
Hi Dave,
Thanks for your answer. We did what you have written. Our scrolling text was already a control, so the only thing that we had to do is adding a thread that does the work to scroll the text. But we have noticed that the OnPaint method (draws the text, and is executed by the Paint event of the form) is executed in the MainThread and not in the new thread that we have created. So the text is drawed on the form in the MainThread. The OnPaint event is triggerd by calling the invalidate method. The handler that says what to do in the MyBase.Paint event is also set in the new thread. Is it possible to execute the OnPaint method in our new created thread?
Thanks in advance,
Kurt
|
|
|
|
|
No, it's not. All drawing happens on the UI thread, no matter what.
I thought you said you moved the long-running operation to a seperate thread and left the Scrolling Text on the UI thread.
Basically, since you have no source code or control over the control that's loading the move, it's going to do it's operation on the UI thread, no matter what you do. The only option you have is to find a control that loads it's data in it's own background thread. I don't know of any off the top of my head.
Basically, you have to get each operation you want running at the same time in it's own thread. All rendering will happen on the UI thread, no matter what. So, if any operation, like loading the movie, happens on the UI thread, all drawing for all other controls, no matter what thread they're on, will stop, until the movie is loaded.
|
|
|
|
|
I'm using the webbrowser control of Microsoft to load a HTML page. When I use this control to load a page, the most of the controls are waiting then for a short time. So this means that the webbrowser control is doing his work in the UI thread? If so, why it's implemented in this way? I think it should be better to do the work of the webbrowser in a seperate thread.
|
|
|
|
|
ambio wrote: When I use this control to load a page, the most of the controls are waiting then for a short time. So this means that the webbrowser control is doing his work in the UI thread?
Yes.
ambio wrote: If so, why it's implemented in this way?
Ask Microsoft.
ambio wrote: I think it should be better to do the work of the webbrowser in a seperate thread.
The WebBrwoser control is an implementation of Internet Explorer, NOT a "from the ground up" purpose built browser control. Your constrained by the limits of IE.
If you want true multithreading, you'll have to write the page downloading stuff yourself. Check into the HttpWebRequest class.
|
|
|
|
|
Ok, thanks for your help and time.
|
|
|
|
|
Hello,
Is it possible to use vb.net transactions with connection to AS400?
Here is a snippet:
objConn.Open()
' Make the transaction.
Dim trans As Odbc.OdbcTransaction = _
objConn.BeginTransaction(IsolationLevel.ReadCommitted)
' Make a Command for this connection
' and this transaction.
Dim cmd As New Odbc.OdbcCommand( _
"UPDATE AUTCTRL SET CTLNM=? WHERE CTLNM=?", _
objConn, _
trans)
' Create parameters for the first command.
cmd.Parameters.Add(New Odbc.OdbcParameter("CTLNM", txtFirstName1.Text))
cmd.Parameters.Add(New Odbc.OdbcParameter("CTLNM", txtLastName1.Text))
' Execute the second command.
cmd.ExecuteNonQuery() '(1) BUG IN THIS LINE
' Create parameters for the second command.
cmd.Parameters.Clear()
cmd.Parameters.Add(New OleDb.OleDbParameter("CTLNM", txtFirstName2.Text))
cmd.Parameters.Add(New OleDb.OleDbParameter("CTLNM", txtLastName2.Text))
' Execute the second command.
cmd.ExecuteNonQuery()
' Commit the transaction.
trans.Commit()
' Close the connection.
objConn.Close()
'(1): ERROR [HY000] [IBM][Client Access Express ODBC Driver (32-bit)][DB2/400 SQL]SQL7008 - AUTCTRL in RAVONLIBT not valid for operation.
Thank you
Shay Noy
|
|
|
|
|
As far as I know, AS400 is a type of IBM computer, not a database. I assume you have a database on there (as you have a connection), so I expect the database either supports these types of transactions or, by the error message, more likely it doesn't. In a nutshell, check your database documentation.
Hope this helps
Bob
Ashfield Consultants Ltd
|
|
|
|
|
I wonder if it is DB2. The only time I used AS400 stuff it was a cobol type environment I think but that was in the 90's.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
It's DB2.
The need to optimize rises from a bad design
|
|
|
|
|
|
|
Hi all,
I am about to develop a client server application in which there can be more than 2000 clients continuously using the application at once.
The rows returned at one time might be of 1000 s as well. Previously in VB 6 I use to use win sock or dart sock for communicating but the projects were not as big as this.
Now i am developing this application in .net 2005 and i went through web and found 3 different approaches of communicating between client and server applications and so I am not being able to choose the right one for me.
In my application i will have one desktop application and one web application. Both of these interfaces can be used by clients which connect to remote server and i need to log the connected users as well.
Then server will process the requests and talk to Active x objects which will be located in different remote location and those active x objects will talk to database and get back the rows and have to return to appropriate client.
Ok now in this scenario what would be better for me to use? please advice advantages and disadvantages of using each of the processes.
thanks in advance
|
|
|
|
|
I would probably use a web service. I beleive remoting will give you a faster response but the environment is more complex to maintain. I'll be interested in other responses.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello to all you gurus and supporters here!
I seem to create some performance trouble when it comes to reading the filenames from a large directory (~ 30 thousand files) into a listview field like that:
Dim TargetFileList As Array
With openDLG
...
If .ShowDialog = Windows.Forms.DialogResult.OK Then
TargetFileList = openDLG.FileNames
Return TargetFileList
End if
End With The applications dialog window freezes for long... long....
Does someone of you probably know a better (i.e. faster) way of reading all of these filenames? The purpose is to find similar names in another directory and display filesInDir1 / missing files / filesInDir2 in different listview fields then.
Thank you for any inspiration
Michael
|
|
|
|
|
There's no way to speed this up. You're already using the system supplied dialog. Really, the problem is in returning a list of 30,000+ filenames and rendering them in the dialog. You'll ahve to write your own, but I doubt you'll see any performance gains that would justify the effort.
|
|
|
|
|
Listview doesn't handle that much items very fast in normal mode. Have a look at ListView.VirtualMode Property[^]
The need to optimize rises from a bad design
|
|
|
|