|
Hello, i need help with this code to make the line visable as drawing and not just after. any help would be great
Public Class Form1
Private lines As New List(Of Line)
Private start As Point
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.PictureBox1.Image = New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height)
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Me.start = e.Location
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
Dim [end] As Point = e.Location
Me.lines.Add(New Line(Me.start, [end]))
Dim area As New Rectangle(Math.Min(Me.start.X, [end].X), _
Math.Min(Me.start.Y, [end].Y), _
Math.Abs(Me.start.X - [end].X), _
Math.Abs(Me.start.Y - [end].Y))
area.Inflate(1, 1)
Me.PictureBox1.Invalidate(area)
Me.PictureBox1.Update()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Me.DrawLines(e.Graphics)
End Sub
Private Sub Save()
Using g As Graphics = Graphics.FromImage(Me.PictureBox1.Image)
Me.DrawLines(g)
End Using
Me.Clear()
End Sub
Private Sub Clear()
Me.lines.Clear()
Me.PictureBox1.Refresh()
End Sub
Private Sub DrawLines(ByVal g As Graphics)
For Each line As Line In Me.lines
g.DrawLine(Pens.Black, line.Start, line.End)
Next line
End Sub
End Class
Public Class Line
Private _start As Point
Private _end As Point
Public Property Start() As Point
Get
Return Me._start
End Get
Set(ByVal value As Point)
Me._start = value
End Set
End Property
Public Property [End]() As Point
Get
Return Me._end
End Get
Set(ByVal value As Point)
Me._end = value
End Set
End Property
Public Sub New()
Me.New(Point.Empty, Point.Empty)
End Sub
Public Sub New(ByVal start As Point, ByVal [end] As Point)
Me._start = start
Me._end = [end]
End Sub
End Class
|
|
|
|
|
Member 9397499 wrote: i need help with this code to make the line visable as drawing and not just after
After "what"? Please describe the current behavior and the desired behavior.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
The program draws a line like the line tool in paint over a picture box sets the line from point a to point b. But in paint for instance the line in visible as you are drawing it from point a to b. In this case the line is only visable after you let the mouse go at point B.
So you can't see the line until after you have it in place.
I would like to see the line being made instead of just after i click a to b.
|
|
|
|
|
See my response to your question. You need to use the correct methods to do the painting if you want it to be permanent.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
That makes more sense; there's quite some examples out there on drawing a rectangle with the mouse. Google for "marching ants" or "rubber band drawing".
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
You are drawing in the wrong part of your code. All drawing must be done in the override of the OnPaint[^] method of the control or form that you are referring to.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Am just a starter and I really need to a lot about API in visual basic 6.0, can any body help me with some notes or anything on it.
|
|
|
|
|
Ainnop wrote: visual basic 6.0
If you are just starting why are you bothering with that ancient unsupported train wreck? Get Visual Studio Express edition for free from Microsoft.
If you really insist that you need VB6 information, then google is probably your best best.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
Well I have vb 8.0 but where do I start from and how do I start, may be you can help me, if you have any Ideas, thank you
|
|
|
|
|
VB8 is called "VB.NET". You start with a good entry-level book, or with the tutorials on the Microsoft[^] site.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Or there are plenty of tutorials on this little place we call CodeProject.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
The program draws a line like the line tool in paint over a picture box sets the line from point a to point b. But in paint for instance the line in visible as you are drawing it from point a to b. In this case the line is only visable after you let the mouse go at point B.
So you can't see the line until after you have it in place.
I would like to see the line being made instead of just after i click a to b.
|
|
|
|
|
And this means exactly what to me?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
|
0
In a visual basic 2008 console application, I need to split up some an extrmely large method into lgocial groups based upon the new logic I need to add. Thus I have the following questions:
1. If i keep the code the way it basically exists in a large method, how can I make the code go to the end of the method? Basically from my if statment certain code would happen and then I want to go to the end of the method.
2. From the place where I would do the if statement, I would break the large method into two methods. From this if statement, i would do the new code or setups the rest of the code into this new method using most of the existing logic. However when I setup this new method, how would I know what objects I need to pass to the new method?
|
|
|
|
|
This problem is not language dependent and it is something we have all had to face at one time or another.
- Bad idea, it means adding more if statements or even using a (shudder)
goto . - Look at your design and break it into logical sections, each of which is self contained. You will easily see which objects are used within each section. That gives you your new methods.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
is there code in vb.net 2008 to say to break out of a loop and go to the end of the method? if so waht is it?
I am a C# programmer and I need to make this change to a VB 2008 application.
|
|
|
|
|
|
dcof wrote: If i keep the code the way it basically exists in a large method, how can I make the code go to the end of the method?
Methods should really not be very large. You need to think about maintainability and readability. If you are lumping everything into one large method, you could start running the risk of having a difficult time debugging the method if something were to go wrong. It does not hurt to look into refactoring the code
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Hello,
I've been thinking about this one for a long time. The following code always gives me an OverflowException when I run it:
Dim x As Byte = 200
Dim y As Byte = 100
Dim z As Byte = (x + y) Mod 256
I know the problem is the fact that I'm adding two byte values together, which is exceeding the limits of the data type in the intermediate step (x + y) before the modulo 256 is performed and the result assigned to z. I can fix it if I do this:
Dim x As Byte = 200
Dim y As Byte = 100
Dim z As Byte = (CInt(x) + CInt(y)) Mod 256
But that just seems like a lot of bother to achieve something that should be simple. One of my latest projects involved a lot of arithmetic like this and I can't help but wonder whether or not there's a better way of performing pure byte arithmetic with modulo operations without resorting to declaring larger integers all over the place or casting to and from them in code.
SixOfTheClock
A programming language is to a programmer what a fine hat is to one who is fond of fancy garden parties. Just don't try wearing any .NET language on your head. Some of them are sharp.
modified 17-Sep-12 5:21am.
|
|
|
|
|
Nope. That's the simplest and fastest way to do it. Well, it'll be a tiny bit faster if you just used integers to begin with.
|
|
|
|
|
Well, couldn't have asked for it any clearer than that! Thank you.
A programming language is to a programmer what a fine hat is to one who is fond of fancy garden parties. Just don't try wearing any .NET language on your head. Some of them are sharp.
|
|
|
|
|
I have created an updater, but I want a way to hide the exe being downloaded, is this possible?
Thanks,
Bryan
modified 16-Sep-12 22:49pm.
|
|
|
|
|
Hi Bryan, just to let you know that nobody here is going to write the code and paste it here for you for two reasons:
1. We're here because we want to help people with specific questions about programming, not take on programming tasks on your behalf. You'll need to hire someone for that.
2. That kind of vagueness makes it impossible for anybody reading your question to know what you're talking about, let alone start to help you out. Do you mean hide the downloaded executable file on-disk? There's no way we can know for sure to give a useful answer unless you're more specific. Then and only then can we help you out.
I direct you to the "How to get an answer to your question" message posted by Chris Maunder. It's up at the top of the message board there. Good luck with your project.
A programming language is to a programmer what a fine hat is to one who is fond of fancy garden parties. Just don't try wearing any .NET language on your head. Some of them are sharp.
|
|
|
|
|
Fixed it, Sorry about that.
|
|
|
|