|
Thank you!
Using Clipboard class I have resolved the most of the problems.
The only menu items that remain is Undo.
What should I check inside the ContextMenu.Popup event , in order to determine that this command should be enable or disable ?
|
|
|
|
|
In both WPF[^] and Windows Forms[^], the TextBox control has a CanUndo property.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hey,
I don't know if you mean you want a code example for disabling the buttons in your Context Menu or your code doesn't work.
If your code doesn't work as it suppose to do just try this (after you disabled for example a button in your context menu):
YourControlName.Refresh
If you mean that you don't have a code, I have a good example.
Private Sub EditPaste_Click(sender As Object, e As EventArgs) Handles EditPaste.Click
Dim iData As IDataObject = Clipboard.GetDataObject()
If iData.GetDataPresent(DataFormats.Text) Then
TextEditorBox.SelectedText = CType(iData.GetData(DataFormats.Text), String)
End If
End Sub
Private Sub EditCut_Click(sender As Object, e As EventArgs) Handles EditCut.Click
If TextEditorBox.SelectedText <> "" Then
Clipboard.SetText(TextEditorBox.SelectedText)
TextEditorBox.SelectedText = ""
Else
MsgBox("Nothing selected")
End If
End Sub
Private Sub EditCopy_Click(sender As Object, e As EventArgs) Handles EditCopy.Click
If TextEditorBox.SelectedText <> "" Then
Clipboard.SetText(TextEditorBox.SelectedText)
Else
MsgBox("Nothing selected")
End If
End Sub
Hopefully your question is awnsered
|
|
|
|
|
Hello !
I have this working code on c# :
var contextMenu = new ContextMenu();
contextMenu.MenuItems.Add(new MenuItem("Copy", (s, ea) => textBox1.Copy()));
contextMenu.MenuItems.Add(new MenuItem("Paste", (s, ea) => textBox1.Paste()));
contextMenu.MenuItems.Add(new MenuItem("Undo", (s, ea) => textBox1.Undo()));
contextMenu.MenuItems.Add(new MenuItem("Select All", (s, ea) => textBox1.SelectAll()));
textBox1.ContextMenu = contextMenu;
I don't know c# , so I have used a code converter , that has produced this code :
Dim contextMenu = New ContextMenu()
contextMenu.MenuItems.Add(New MenuItem("Copy", Function(s, ea) textBox1.Copy()))
contextMenu.MenuItems.Add(New MenuItem("Paste", Function(s, ea) textBox1.Paste()))
contextMenu.MenuItems.Add(New MenuItem("Undo", Function(s, ea) textBox1.Undo()))
contextMenu.MenuItems.Add(New MenuItem("Select All", Function(s, ea) textBox1.SelectAll()))
textBox1.ContextMenu = contextMenu
But this code code is not working , and produce an error on :
textBox1.Copy()
Exression doesn't produce a value
A similar error is producet in other rows.
What can I do ?
Thank you !
|
|
|
|
|
Your code converter is wrong - it should be creating Sub() as these functions don't return any value.
Dim contextMenu = New ContextMenu()
contextMenu.MenuItems.Add(New MenuItem("Copy", Sub(s, ea) textBox1.Copy()))
contextMenu.MenuItems.Add(New MenuItem("Paste", Sub(s, ea) textBox1.Paste()))
contextMenu.MenuItems.Add(New MenuItem("Undo", Sub(s, ea) textBox1.Undo()))
contextMenu.MenuItems.Add(New MenuItem("Select All", Sub(s, ea) textBox1.SelectAll()))
textBox1.ContextMenu = contextMenu
|
|
|
|
|
I use the following for populating a Combobox.
Dim comboSource As New Dictionary(Of String, String)()
Dim k as string
public sub load CBox()
comboSource.Add("xxx", "Ex")
comboSource.Add("yyy", "Ypsilon")
comboSource.Add("zzz", "Zet")
ComboBox2.DataSource = New BindingSource(comboSource, Nothing)
ComboBox2.DisplayMember = "Value"
ComboBox2.ValueMember = "Key"
end sub
Then from the code, when I need to get the key I use
k = DirectCast(ComboBox2.SelectedItem, KeyValuePair(Of String, String)).Key
and this works til here...
My problem is about the ComboBox2 listed values...
The first time I open the form containing the combobox I get the 3 values correctly listed in it.
But if I close this form and reopen it, the combobox list is empty and the DirectCast(ComboBox2.SelectedItem, KeyValuePair(Of String, String)).Key will not return anything...
Tried many things but can't figure out.
Any help is appreciated.
SepPax
|
|
|
|
|
Hi
I want to upload my excel file (Sheet1) to DataGridview Control.
This excel file will come with different format(2003,2007,2010), and want to preview and if I make changes in Datagridview control, also should make changes to excel file.
|
|
|
|
|
And - what have you tried[^] so far?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|
Hello !
I'm using vb.net 2013 , and I have configured Shutdown mode to " When last form is closed".
On my main form , I have a menu item which have this code to close application :
Application.exit
Everything is working fine , except one case :
When I open a specific form , where a Combobox is created on runtime on specific position , and I've used Addhandler several time for several Event.
The combobox is created when pressing a button.
When I open this form and I doesn't press the button, everything is working ok.
When the combobox is created , when I close this form , and try to close the application using the menu , nothing is happened. The application is not closed and no error message is displayed.
On the form close event , I try to put a line of code :
MyCombobox.dispose()
But the situation is the same.
What can I do ?
Thank you !
|
|
|
|
|
As a first suggestion: Make sure you unsubscribe from all event sources (like your ComboBox but not only) before they go out of scope.
I had a very similar problem not too long ago but unfortunately I don't remember exactly what I did to fix it. I remember though that it involved eventhandlers not being unsubscribed.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
but this is not done automatically when I do Combobox.dispose ?
|
|
|
|
|
satc wrote: but this is not done automatically when I do Combobox.dispose ? I don't think so - I assume the references in the event sources are alive until the Combobox object gets garbage collected. (edit: If someone else comes along here, can you confirm this?)
But, while explicitly unsubscribing is good practice in general (as long as you're not using a weak event pattern), it might not be the cause for your current problem. Can you post the relevant code bits? (Include also creating/referencing code)
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
modified 18-May-15 14:09pm.
|
|
|
|
|
I have unsubscribed to all events.
It's the same situation.
|
|
|
|
|
Does there still exist another form that is "hidden", instead of closed?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
no , all the forms are closed , and I repeat that if I open the same form , but without creating the combobox , everything works ok.
|
|
|
|
|
Did you consider my suggestion to post your code?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Please , can you make more clear what is the code that you want ?
on my main form Menuitem that close the application , I have only :
Application.Exit
On the form where I use the combobox , on the close event I have only the code that unsubscribe from all event and Combobox.dispose.
|
|
|
|
|
.
modified 18-May-15 1:50am.
|
|
|
|
|
|
Emm, thanks. The problem is I'm on a level where copying text from one textbox to another by usign a button is quite an achievement and analysing somebody else's project isn't something I could benefit from right now.
|
|
|
|
|
Hi.. I just made a vb.net project. My problem is that, how can i automatically resize the image size (height and width) when inserting in a picturebox? For example, the image i have on my picturebox is 128x128. Now, before i save that image to my sql database, i want the image size to become 100x100... How to do that? Please, i need your help... Thanks...
|
|
|
|
|
Give your picturebox the size of 100x100 and set it to "zoom". See MSDN[^] for details.
The easy way;
Dim resizedBitmap As Bitmap = New Bitmap(originalImage, new Size(100, 100));
If you need more control over the quality of the result, try the answer by Mark[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
modified 17-May-15 12:40pm.
|
|
|
|
|
That only displays the bitmap in the new size. OP is asking how to actually resize the bitmap.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
You're right; I did not read as carefully as I should have
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|