|
|
If you mean the Button1 handler should modify the Button1 text, then I see no problem, that works just fine. Mind you, you will see the results only after the Click handler has finished (unless you add a call to Refresh). So changing the text initially, performing a long operation, then changing the text back to its original, all in the one Click handler, will not show any change at all. But then, you shouldn't be doing long operations inside a handler on the GUI thread to begin with... Threads (and BackgroundWorkers) were invented to decouple long operations from the GUI thread.
|
|
|
|
|
I did add refresh() at the end... but that didn't work
|
|
|
|
|
Then you are doing something wrong. Maybe you have more than one Button1 in your project, and you're talking to the wrong one (it helps to use meaningful names). Maybe its initial text isn't neither "0" nor "1". Maybe ...
You will need to provide a more comprehensive description of what you have if you want to get more effective help around here.
|
|
|
|
|
|
Sorry, I am not going to download, unpack, and investigate a bunch of code, and neither would anyone else around here. If you want effective help, put some effort in describing the problem properly and provide the relevant pieces of code (inside your message, and using PRE tags), not just all of it.
|
|
|
|
|
Alright. So here is the exact issue with all the pictures and everything.
I have a Form which has a FlowLayoutPanel, which has a UserControl on it. That Usercontrol has a Button on it.
The initial text of that Button is "0"
But I want to change that to "1" if it is a "0" and change it back to "0" if it is a "1"
So this is the code I used on the UserControl which has the Button on it:
Public Class UserControl1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "0" Then
Button1.Text = "1"
ElseIf Button1.Text = "1" Then
Button1.Text = "0"
End If
End Sub
End Class
But when I click on Button1, the event does get fired but the text of the Button1, that is on the UserControl which is drawn on FlowLayoutPanel doesn't get changed.
|
|
|
|
|
First, you don't need ElseIf in this case. It should just be:
If Button1.Text = "0" Then
Button1.Text = "1"
Else
Button1.Text = "0"
End If
Second, Button1 is a horrible name for a button. Change it to something meaningful, like "OkButton", so you know without thinking which button it's referring to on your form.
|
|
|
|
|
|
I have no idea what you're doing wrong because this works fine. I wiped up this little example in about a minute:
Private Sub TestButton_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles TestButton.MouseDown
ChangeButtonText(TestButton)
End Sub
Private Sub TestButton_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles TestButton.MouseUp
ChangeButtonText(TestButton)
End Sub
Private Sub ChangeButtonText(ByRef target As Button)
If target.Text = "0" Then
target.Text = "1"
Else
target.Text = "0"
End If
End Sub
If you want the button to change text like a toggle, just remove the MouseUp handler.
Truthfully, I'd be creating my own button control to wrap this functionality and overriding the OnMouseDown and OnMouseUp methods to do this. I wouldn't be doing it using event handlers.
But, since this method is easier to understand, here you go...
|
|
|
|
|
That worked beautifully BIG THANKS M8!
|
|
|
|
|
Dear ammar ahmad
there was no user control name usercontrol1 in your solution.
I saw your coding,you are more expert than me.
I didnt run your program at all.
Would you please tell me what this code is for?
|
|
|
|
|
It is there... it should be under Form1.
This is Twitter client that I am working on.
|
|
|
|
|
Try changing the sub to:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "0" Then
Button1.Text = "1"
Else
Button1.Text = "0"
End If
End Sub
|
|
|
|
|
|
Oke i know this sounds a bit basic but have you checked for spaces? strings are quite picky with those. "0 " is not the same as "0" for them. tough its likely a human will read over that last space.
you could add a replace to the .text to get rid of this problem.
If Button1.Text.Replace(" ","") = "1" then
Button1.Text = "0"
Elseif Button1.Text.Replace(" ","") = "0" then
Button1.Text = "1"
End if
EDIT: oke reading some more and i hear some rumors that your using several threads. if this thing is executed in a thread you might want to enforce the update to your gui.
Private Sub updateUI()
If Me.InvokeRequired Then
Me.Invoke(New MethodInvoker(AddressOf updateUI))
Else
Me.Update()
End If
End Sub
if your using that button thing in a sub/background thread then add the above sub and try calling it after the button event is done. be aware that this isn't good code and will enforce a full refresh of your screen, its a nice way to test tough.
|
|
|
|
|
Thanks Nick. But the issue has already been resolved
|
|
|
|
|
Hi,
Currently when I add a new control to the FlowLayoutPanel1, it gets added to the bottom of all the previous controls that were added in FlowLayoutPanel1. Is there a way that I can add the new controls to the top of FlowLayoutPanel1?
I have added a small diagram of what I want:
http://foto.pk/images/havewant.png[^]
Please note that the flowdirection property isn't giving me the effect that I need. Because new items (controls) are added while the app is running.
Source code of the application added:
http://www.mediafire.com/?1uo8zd3ybgdmiwp[^]
*Note: The above download has all the twitter keys for my account so you don't have to make a new account or anything. Please don't misuse it.
Can you please add that feature that I want in the source?
modified 22-Jun-12 9:23am.
|
|
|
|
|
Hey,
Have you try'd settings the index of the new control?
FlowLayoutPanel1.Controls.SetChildIndex(Button1, 0)
Here button1 is my control as control and 0 (int) is the new index of the control in the flowlayoutpanel.
|
|
|
|
|
Not quiet sure how that is done as I am new to controls and flowlayoutpanel.
Here is the code that adds the tweets(items) into the control that I have made:
Private Sub AddTestTweet(ByVal tweet As TwitterStatus)
If (Me.FlowLayoutPanel1.InvokeRequired) Then
Me.FlowLayoutPanel1.Invoke(New AddTestTweetDelegate(AddressOf AddTestTweet), tweet)
Else
Console.WriteLine(String.Format("New tweet: @{0}: {1}", tweet.User.ScreenName, tweet.Text))
Me.FlowLayoutPanel1.Controls.Add(New TweetTimelineControl(tweet))
End If
End Sub
Private Sub NewTweet(ByVal tweet As TwitterStatus)
On Error Resume Next
AddTestTweet(tweet)
End Sub
And here is the control:
Public Class TweetTimelineControl
Public Sub New(ByVal status As TwitterStatus)
Me.InitializeComponent()
Me.userPictureBox.LoadAsync(status.User.ProfileImageLocation)
Me.UserNameLabel.Text = status.User.ScreenName
Me.Label2.Text = status.CreatedDate.ToShortDateString()
Me.DateLabel.Text = status.CreatedDate.ToShortTimeString()
Me.TextLabel.Text = status.Text
Me.Label1.Text = "Number Of Retweets: " & status.RetweetCountString
End Sub
End Class
Can you please tell me how to do this on the code given above?
|
|
|
|
|
Hey
I gotte say i dont know your program so this is a bit of guessing. But from what you send i would suggest you place the code into your AddTestTweet sub.
Private Sub AddTestTweet(ByVal tweet As TwitterStatus)
If (Me.FlowLayoutPanel1.InvokeRequired) Then
Me.FlowLayoutPanel1.Invoke(New AddTestTweetDelegate(AddressOf AddTestTweet), tweet)
Else
Console.WriteLine(String.Format("New tweet: @{0}: {1}", tweet.User.ScreenName, tweet.Text))
Me.FlowLayoutPanel1.Controls.Add(New TweetTimelineControl(tweet))
End If
End Sub
|
|
|
|
|
Nope. Still don't get it.
Here I have uploaded the entire source code:
http://www.mediafire.com/?1uo8zd3ybgdmiwp[^]
*Note: The above download has all the twitter keys for my account so you don't have to make a new account or anything. Please don't misuse it.
Can you please add that feature that I want in the source?
modified 22-Jun-12 9:22am.
|
|
|
|
|
I got the file, so you can remove the link if you want. Cant promise i can get to it ASAP, but i will see if i can paste in the code you need.
EDIT:
Oke got a quick look at it during work. the twitter is blocked here so i cant actually test it. but i think if you replace your AddTestTweet sub with this one it will work.
Private Sub AddTestTweet(ByVal tweet As TwitterStatus)
If (Me.FlowLayoutPanel1.InvokeRequired) Then
Me.FlowLayoutPanel1.Invoke(New AddTestTweetDelegate(AddressOf AddTestTweet), tweet)
Else
Console.WriteLine(String.Format("New tweet: @{0}: {1}", tweet.User.ScreenName, tweet.Text))
Dim storedtweet As New TweetTimelineControl(tweet)
Me.FlowLayoutPanel1.Controls.Add(storedtweet)
Me.FlowLayoutPanel1.Controls.SetChildIndex(storedtweet, 0)
End If
End Sub
Like i said its untested so don't shoot me if it adds to the bottom, try playing with the 0 if this happends(make it FlowLayoutPanel1.Controls.Count for example).
modified 22-Jun-12 9:20am.
|
|
|
|
|
Alright. Thanks.
modified 22-Jun-12 9:22am.
|
|
|
|
|
Edited my last message with a possible solution.
|
|
|
|