the question is rather simple, but what I am working on is not..
this is a marker from a control called GMaps.NET
the next picture is a form, that follows the marker when I drag the map, something like the InfoWindow on google maps API.
only problem is that, it covers the marker, and I can't offset it no matter how hard I think.
this is my current code..
Private Sub map_OnMapDrag() Handles map.OnMapDrag
Form2.Show()
Form2.Location = camera1.LocalPosition
End Sub
please list some ways on how I can offset it so we can see the marker.. thanks!
Reminder : you can't directly use camera1.LocalPosition's Point because its coordinates are inside the map. whilst Form2.Location is on the form. though the same value, they are worlds apart :)
so give different options that I can try TIA
Try out Form2.Location.Offset(dx, dy)
Related
I want my Richtextbox to be always at the bottom and "autoscroll" to the end.
I found this with some google searches:
Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
RichTextBox1.SelectionStart = RichTextBox1.TextLength
RichTextBox1.ScrollToCaret()
End Sub
This seems to work but as the text updates it jumps to the top of the box and with another update to the bottom. Can someone help me out? Or is there a better method to keep the Textbox at the end?
Thanks,
Max
Your code kind of works- What I would suggest to solve your initial problem is to alter your code slightly and add
RichTextBox1.SuspendLayout()
at the beginning of your sub, and
RichTextBox1.ResumeLayout()
at the end.
However, if your cursor isn't on the last line and you type something, the character will appear at the cursor before moving to the end of the text. I'm guessing you don't want that behaviour - In which case you should add the code into a KeyPress event.
There are several possible behaviours. Do you want to be able to type anywhere, or only at the end of the text? Or just to place the cursor at the end under certain circumstances - for example when the RichTextBox is first populated with a bunch of text? Or maybe something else.
The simplest solution would be for the user just to press the keys Ctrl-End. That doesnt need any code at all.
Using either the Designer properties or by programming it directly, I cannot seem to get a tool tip to display the way I thought I should be able when I hover over the control.
For instance, although I can display the text I want, no matter what I set as the AutoPopDelay (I want 30 seconds) or as the background color (I want a Yellow), the tool tip always comes up for the default 5 seconds on a gray background only.
Below is the sub that I programmed. What am I missing?:
Private Sub lblUploadFileTypeHelp_MouseHover(sender As Object, e As EventArgs) Handles lblUploadFileTypeHelp.MouseHover
ToolTip1.OwnerDraw = True
ToolTip1.IsBalloon = True
ToolTip1.BackColor = Color.LemonChiffon
ToolTip1.AutoPopDelay = 30000
ToolTip1.Show("Sample text to display", lblUploadFileTypeHelp)
End Sub
IsBalloon is being taken into consideration before OwnerDraw.
You would need to handle your own drawing to get a custom display.
Have a look at the MSDN code sample MSDN Tooltip
I had searched a lot how to display a Msgbox that will not wait the user input (pressing ok or cancel).
I found 3 solutiuons to this.
1- Display the MsgBox() in another thread or using BackgroundWorker()
2- Create a form that display the message, then closed the form by a timer and use it instead of Msgbox()
3- Using the API MessageBoxA()
Let say I have a loop from 1 to 100, and I want display a message for the i(counter)
When I test above 3 ways, I found that this is not the right way of doing it, I don't need a msgbox() to close by it self after showing the message, because that will display 100 dialog.
What I realy want is to display ONLY 1 MsgBox() and change the text accordingly.
I managed to do this using a a Form() as class and I did it using Application.DoEvents
I know it can be done using BackgroundWorker or Threading since alot of people advice against using Application.Doevents
Here is my code
Dim oWW As New WaitWindow With {.TopLevel = True,.TopMost = True,.StartPosition = FormStartPosition.CenterScreen}
oWW.Show(Me)
For i = 1 to 100
Threading.Thread.Sleep(500) ' Just to slowdown execution
oWW.SetMessage("Counter = " + i.ToString)
Next
oWW.Dispose()
Public Class WaitWindow
Sub SetMessage(ByVal Message As string)
lbl_message.Text = Message
Application.DoEvents
End Sub
End Class
WaitWindow is not more than a Form base class with a label (lbl_message)
That code works fine (display WaitWindowForm on center of currently displayed form only once, then I change the text)
I have 3 questions :
1- How to display the WaitWindowForm in the top right corner of my working form?
2- Is it possible to display the normal MsgBox() or MessageBox.Show() only once, then capture the text displayed and change it?
3- Which one is suitable for my issue (BackGroundWorker or Threading) and what the code in WaitWindow class I post will be if I decided to use Backgroundworker or Threading instead of Application.DoEvents (Changing the label text not showing new form with new text) ?
3 questions in one post.. humm.. who cares, I am not the one who will answer lol :)
Thanks in advance.
I think the issue that you're really encountering is that you're trying to use a message box for something it's not suited for. If you want to have text that constantly changes just add a text box in the upper right corner of your application and adjust it every time a new message needs to be shown.
You can also look up dialogu windows (search ".showdialog() vb.net" in google) might help as well.
I am new to VB.NET. I am developing a game in which the user has to guess the name of the image that appears in a picturebox. The user has to enter the answer in a textbox. If it is right, a button appears and changes the image of the picturebox.
I would like the image of the picturebox to change when the next level button is clicked. I want to make an array which will contain all the images with a string as the answer.
How would I go about changing the image to the next in the array after each next level button click?
Thanks
To Load images to array
Dim imgPictures(8) As Image
imgPictures(0) = Bitmap.FromFile("Filename")
To display images.
Dim i as integer = 0
Next Image
myPictureBox.Image = imgPictures(i++)
Previous Image
myPictureBox.Image = imgPictures(i--)
Make sure you are checking for maximum and minimum array values, otherwise you will get indexoutofrange exceptions.
It's hard to tell exactly what parts of the code you need help with, so I'm guessing here. I went in a different direction than #Anuraj, which hopefully is helpful.
Let's say you create an object-based array:
Dim arr(10) As Object
You then create a Sub in your code that will handle the "next level" button's click event:
Private Sub NextLevelButton(ByVal sender As Object, ByVal e As RoutedEventArgs)
'Do Stuff
End Sub
Now replace 'Do Stuff with code that retrieves the next item in the array, and then changes the image in the UI. Obviously, to do this, you'll need to know which item in the array was most recently used. The easiest way to do this is to create a global variable (outside of all subs in your code) which you will replace each time you add a new image to the UI. The value of this global variable will be the index number of the most recently used image in your array. Then, you just increment by one and grab the next image.
I don't find a CanGrow property on the Textbox control. This is common in some other controls, and what it does is expand the control to acomodate more data. Anyway to get this feature in the TextBox?
Well, I came up with this:
Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox.TextChanged
'check to see if textbox has text
If (TextBox.TextLength > 0) Then
'resize height of textbox by count of lines (plus add some padding)
TextBox.ClientSize = New Size(TextBox.ClientSize.Width, Convert.ToInt32((TextBox.Lines.Length * TextBox.Font.Height) + (TextBox.Font.Height * 0.5)))
Else
'resize to one line height (plus padding)
TextBox.ClientSize = New Size(TextBox.ClientSize.Width, Convert.ToInt32(TextBox.Font.Height + (TextBox.Font.Height * 0.5)))
End If
End Sub
Note: it doesn't work with word-warp.
I'm not familiar with CanGrow. Are you looking for Anchor property perhaps?
Anyway to get this feature in the
TextBox?
Well, yes, but, you may need to look into doing this manually. The Graphic.MeasureString() function may be what you are looking for in order to set the width properly.
Keep in mind that MeasureSting may have issues measuring multiline strings.
If you set the anchor properties to top,left,bottom,right then the control will grow as the form resizes.
I think a better option is to use docking though. I usually set up a panel layout with one docked to client, then I put the control I want resized in the panel docked to client, and set the control to dock to client as well.