|
Using code only;
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
Dim b As New Button()
b.Parent = Me
b.Location = New Point(0, 0)
Controls.Add(b)
Dim c As New CheckBox()
c.Parent = Me
c.Location = New Point(0, 0 + b.Height)
Controls.Add(c)
AddHandler b.Click, New EventHandler(AddressOf MyDragEventHandler)
AddHandler c.Click, New EventHandler(AddressOf MyDragEventHandler)
End Sub
Private Sub MyDragEventHandler(sender As Object, e As EventArgs)
System.Diagnostics.Debug.WriteLine(sender.ToString() & " iz clicked")
End Sub
End Class
Or, if you want to do it from the IDE, try these steps;
- Drag a button and a checkbox to the form
- Go to the properties of the button, and switch to "events" view (button looks like lightning)
- Double-click on the
Click event, and write your code
- Go back to the designer, and select the checkbox
- Properties, events-view; there's a combobox next to the
Click event - open it, and select the item "Button1Click"
That should do it
I are Troll
|
|
|
|
|
Thank you very much for your code.
But sorry I didn't fully get it.
If I create a GroupBox1 in Form1, and add textBox1, textBox2 and textBox3 to the GroupBox1, textBox3 is dependent to textBox1 (updated in textBox1_Leave).
then I hook up these controls to MyDragEventHandler, for example I click textBox1, MyDragEventHandler handler will be called. then I input data to textBox1, if I don't click textBox2 or textBox3, instead, I click form or GroupBox1, the cursor is still in textBox1, the dependency of textBox3 cannot be updated since textBox1_Leave is not fired.
If my understanding is wrong, please point it out. very appreciate.
|
|
|
|
|
Your understanding is correct. A groupbox doesn't receive focus when you click it, and TextBox1 is still the active control. (The cursor is still blinking in that textbox, right?)
The Leave event is fired when the input-focus changes within your application. That happens when the user clicks a button, or moves the cursor to some other textbox. There's no way to indicate that someone is "finished" with typing in a textbox except for waiting until the focus moves away.
FWIW, you can set the ActiveControl property to Nothing if the user presses the enter-key.
What functionality are you trying to achieve? If you want to validate the contents of the input, that has it's own event. Take a look here[^] at the order in which events are fired, perhaps there's another way to achieve what you want
I are Troll
|
|
|
|
|
Eddy,
What I try to acheve it that:
If user input negative value, the textBox3 will be disabled, otherwise, textBox3 is enabled.
So if I input negative value to textBox1, but didn't click other controls, the textBox1_Leave not fired, then the textBox3 is still enabled.
Normally how you handle this case of case?
|
|
|
|
|
Andraw Tang wrote: Normally how you handle this case of case?
I'd go for the Validating event, with code similar to below;
1 Public Partial Class MainForm
2 Inherits Form
3 Private t As New TextBox()
4 Private t2 As New TextBox()
5
6 Public Sub New()
7
8 t2.Parent = Me
9 t2.Location = New Point(0, 0)
10
11
12 t.Parent = Me
13 t.Location = New Point(0, 0 + t2.Height)
14
15 Controls.AddRange(New Control() {t, t2})
16
17
18 AddHandler t.Validating, New CancelEventHandler(AddressOf t_Validating)
19 End Sub
20
21 Private Sub t_Validating(sender As Object, e As CancelEventArgs)
22
23 Dim senderAsTextBox As TextBox = TryCast(sender, TextBox)
24
25
26 Dim IsContentValid As Boolean = senderAsTextBox.Text.Contains("-")
27
28
29 e.Cancel = IsContentValid
30
31
32
33 t2.Enabled = Not IsContentValid
34
35
36 If IsContentValid Then
37 System.Media.SystemSounds.Beep.Play()
38 End If
39 End Sub
40 End Class
That will allow the user to switch to another program (to lookup the correct value on the internetz, for example), but it won't allow the user to do anything (like clicking a button in your program or closing it) until the textbox has a valid value.
To achieve what you requested, remove line #29.
I are Troll
|
|
|
|
|
Eddy,
Thank you very much, I will try tomorrow and let you know the result.
|
|
|
|
|
You're welcome, and sleep well
|
|
|
|
|
leave event is fired only when ur focus is left from that control
|
|
|
|
|
Yes, when focus only leave the control when I click other control, do you know how can I let focus leave control when I click other place instead of control on the form?
Thanks!
|
|
|
|
|
I'm trying to delete a file on a remote server using VB.Net and the File.Delete method but I get an Access Denied Exception. I have full Admin rights to the server and file in question and I have no issues deleting the file using windows explorer. I can also delete files and folders on the server, it's just files in one particular folder that causes the issue, and no the file does not appear to be in use.
The code looks something like this...
Imports System.IO.File
Imports System.IO
if file.exists(path) then
try
file.delete(path)
msgbox("File Deleted")
catch ex as exception
msgbox("Unable to Delete File!")
end try
else
msgbox("File Doesn't Exist!")
end if
Please Help.
|
|
|
|
|
have you looked at the Ex.Message in your Try-Catch block ?
Does it give you more information ?
|
|
|
|
|
Access to the path is denied.
|
|
|
|
|
Is there any other process who has locked it?
|
|
|
|
|
No, there is nothing (that I know of) locking it. As I said, I can delete it in explorer no problem.
|
|
|
|
|
98fireblade wrote: catch ex as exception
msgbox("Unable to Delete File!")
end try
this is stupid. There is an exception that typically holds a lot of information, but what the heck, you know best and replace it by a simple sentence providing no clue to the user at all.
Always output Exception.ToString() to either the user or at least a log file, have a look at it, and probably find what is going on.
98fireblade wrote: no the file does not appear to be in use
That is a conjecture, not a fact. Proof it right or wrong.
98fireblade wrote: in one particular folder
if one folder is special, maybe telling us the path, and/or whatever you have done to its security, could help us help you. And do tell us what Operating System you're on, it may provide a clue.
And here for the surprise: if all else fails, add some code to try delete, wait 5 seconds, and try delete again.
|
|
|
|
|
Get off you high horse, we can't all be bloody genius's!
I said the code looks something like this, I supplied the exception which was "Access to the path was denied." which is basically all the information in the catch. I'm also relatively new to the .Net environment, so more help, less attitude would be nice...
When I said the file doesn't appear to be in use, it's not being locked by any user or process, and as stated I can delete it via windows so Security and permissions don't appear to be the issue.
The same piece of code deletes other files and folders on the same remote server without issue.
To answer your OS request, XPSP3 on the machine running the code, and Windows Server 2K3SP2 on the Remote Server.
Just for the record, it's an SMS Compressed file I'm trying to Delete.
|
|
|
|
|
98fireblade wrote: Get off you high horse, we can't all be bloody genius's!I said the code looks something like this
"Something like this" doesn't compile, the machine needs a syntactical correct answer. The devil and the bugs are always in the details, and picking on details needs to become a compulsory habit.
Second, if you move your arse close to a fire, you won't be given a nice advice, but someone will yank your arm and pull you away. That's what just happened.
Back on topic;
- I'd like to see the VB6 code
- I'd like to see console-apps in both languages that attempt to delete the file
- I'd like to see the results of a test on the exact same file.
- I'd like to see the exception. And inner exceptions, if present.
That might sound boring, but it always works
I are Troll
|
|
|
|
|
Are you running this code in a windows service app??
|
|
|
|
|
It's just a normal windows form project if that helps.
|
|
|
|
|
Just another note, I'm upgrading a application I wrote in VB6 to .Net, and the VB6 version deleted this file no problem.
|
|
|
|
|
If it is the (almost) exact same code, you might want to examine the "path" parameter on both your VB6 and VB.Net apps to check for surprises...
|
|
|
|
|
MathmL control for math operations in vb.net project development
Hi ,
Is any one created the MathML based projects in vb.net and how we incorporate in vb.net webbrowser control
Regards,
Selva
modified on Tuesday, August 17, 2010 8:08 AM
|
|
|
|
|
Please edit your question so it is readable, best by removing the tags around your text.
It's time for a new signature.
|
|
|
|
|
|
|