C# - WinForms UserControl How Do I Stop The Control Receiving Focus?
Nov 7, 2011
I have a custom UserControl that contains just one TextBox. When I set the control to Enabled = False, the TextBox is disabled but the control is not (control still fires the Enter event).
How do I ensure that the UserControl will not receive focus?My Enabled Property Looks like this:
Private _Enabled As Boolean = True
Public Shadows Property Enabled As Boolean
Get
Return _Enabled
End Get
[Code]...
View 2 Replies
ADVERTISEMENT
Mar 17, 2010
I am working on a data entry type form and I want the enter key to move focus to the next text box. I've got that working great except that the focus is moving to the label that is, in sequence, between the text boxes.
View 14 Replies
Mar 18, 2009
How do I find out which control has focus in winforms?
View 4 Replies
Jan 30, 2011
There is a panel which contains 2 components: a label and a TreeView. The hierarchy, obviously, looks like this:panel1 // handles Enter event
- label1
- treeView1
I need to do some UI updates when user starts interacting with any of these 3 controls. My attempted strategy was to catch the Enter event of the panel, which would fire when user clicks a label, or TreeView. This way, I can write only one (1) event handler instead of several. While it worked for the TreeView, it didn't work for the label. When I click the label, I don't get the Enter event on the panel. Whats different about the label control? I could handle the Click event of the label. At the same time, I wonder what the other solutions might be.
View 1 Replies
Dec 14, 2010
I have set a scrollable control's autoscroll to true. What do you do when you don't want a scroll to occur? For example, suppose you have a RichTextBox and a button side by side as below:
Notice that "button1" has the focus. If you click on the RichTextBox to give it focus, the scroll bars will scroll until the upper left corner of the RichTextBox is in view.
But what if, for whatever reason, you wanted to keep button1 in view? How would you do that?
View 6 Replies
Jan 25, 2012
I believe I have found a solution! I will be continuing testing to make sure it DOES in fact work, but I'm hopeful :) I have detailed how I found the solution in EDIT THREE of the question.
For anyone wishing to know the full background behind my problem and what I have kind of tried as a result of input from this question, see this: [url]
I will be editing this frequently (>3 times a day most weekdays) as I progress my research and situation, so keep checking back if you are interested or have some information or knowledge of my issue :)
Quick Background:
I have this app I have made that can be crashed by changing my screen saver or locking my work station, and in general whenever a WM_WININICHANGE/WM_SETTINGSCHANGE message is sent to it.
If I can consistently crash my app by changing my screensaver, then SOME part of doing that is sending my app SOME kind of message (not necessarily a windows message, I mean message in the most general sense), which in turn is catastrophic to my application. Due to this, I am trying to find a way to block whatever message is causing my problem from being processed by my application. I am aware this isn't the best way to go about a solution, so you don't need to tell me. Look at the backgroung info or ask why if that bothers you (there is a good reason).
View 2 Replies
Jan 23, 2009
I am working on a client/server application. Everything seems to go well for a while (a few hrs, a few mins its kind of random) then suddenly clients stop receiving data. maybe 1 or two, or all of them. in the end I end up having to restart the server piece to resolve it, but I am trying to understand why its doing this. I've added try catches around the send piece, but it doesnt error out. When the app fires, the listener is started on its own thread. When a new connection is made, that connection is passed to a class that handles all of my connection data(send/receive, responding to commands, etc). The class is started in its own thread, so each connection is running in its own memory space. This issue seems to happen with 1 client connected, or 20, it doesn't really seem to matter.
This causes other issues, like a customer who thinks he is disconnected, will shut down his app, which is supposed to send a command to close the connection on the server side which it does not., so now I have several "closed" connections still open on the server, which is obviously also bad. Another thing I dont get is that it worked fine when I was developing the pieces on my dev box, so I dont get why I have all of these "timeout" issues now. (I put that in quotes, because the timeout period is the default of 10 mins, and I xmit data, at LEAST every minute when the server pushes data updates to all clients)
Here is some of the relevant code
vb
'Command Object, this holds all of the command information being passed back and forth to tell the server what to do, and as well as hold the response.
'The strCMD is the command, strParms is the parameters of the command, obj is ANY object I want to send along with this information
<Serializable()> Public Structure CommandData
Public strCMD As String
[Code] .....
View 7 Replies
May 8, 2009
I have an WinForms app that requires Name/Address data in lots of places, so I decided it would be a good idea to create a User Control. So far, so good. My problem is this: Let's say that my UserControl presents 2 text boxes (txtFName and txtLName) and txtLName is mandatory. What I want to do is put the validation code, e.g.: Code:If txtLName.Text.Length = 0 ThenMessagebox.Show("Enter a last name")End If
[Code]...
View 6 Replies
Dec 28, 2011
I'm trying to create a grid usercontrol.This means that when i press "UP" it goes to the cell above (...so on for all directions) tab goes to the right and enter goes down.Now all these keys (excluding enter) change control focus so i've got a problem using them.How can i lock focus on the control so that these keys won't change it and so that i can use these keys for other things?
View 5 Replies
Jan 15, 2012
A form's key events will fire when you press a key. Place a control on that form and it won't happen any more because that control has focus. There are exceptions to this however as you will see if you place just a h or v scrollbar on the form. The key event will fire because the scrollbars can't receive focus as is demonstrated by the following
Private Sub ScrollBar1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles VScrollBar1.GotFocus
Debug.Print("Scroll GF")
End Sub
[code]....
So I've made my own special scrollbar usercontrol and i can't figure out how to have it leave the key events alone. I'm pretty sure that the problem is that my usercontrol can receive focus at the moment.
I found that the way of doing this is "SetStyle(Windows.Forms.ControlStyles.Selectable, False)". I put that in the new event of my usercontrol and now it looks like this:
Public Sub New()
' This call is required by the designer.
InitializeComponent()
View 4 Replies
Mar 4, 2010
I'm trying to save some layouts from DevExpress Grid Controls so that users can change the layouts and reload them in at a later use of the control.
My question is this for speed issues I am loading the control via a user control inside of a form. Now my problem is I am creating the control by adding an instance of the control to a panel control inside of a tabbed group control when the tab is made visible and then clearing the control when the control is hidden.
If ClaimsGridPanelControl.Visible = True Then
ClaimsGridPanelControl.Controls.Add(New RXClaimsGridControl(ClaimsBindingSource))
Else
ClaimsGridPanelControl.Controls.Clear()
End If
So inside of the RxClaimGridControl I need to call a SaveLayout method when I am clearing the control. But there is no event, at least that I can find, that triggers when a usercontrol is removed/closed/hidden.
My thoughts for handling the .Clear() would be to raise an event in the parent control and then to handle that event inside of the user control.
Is there some event that I am missing in regards to the removal/closing/hiding of a user control, or is there a better way to do this.
View 2 Replies
Apr 25, 2012
I've got an MDI form with child forms that I'd like to refactor to a single form with a tab control containing child controls, in order to move away from MDI clunkiness. When looking at converting the child forms into child controls (or usercontrols), I do see that I'd lose the FormClosing event, which some of the child forms use.
I can override Dispose to handle some of the functionality, but in some cases I'd like to cancel the closing event. Also, I'd like this event to be called before the control is closed even when the form it's on isn't closing, so wiring the control to the form's closing event isn't an option.
[Code]...
View 2 Replies
Apr 2, 2010
[URL]its a free hoster, so you have to wait 10 seconds.First here's the steps to replicate, then I'll explain what the problem is:
(1) Create a System.Windows.Forms.UserControl and add a button to the bottom-right hand corner. Leave the button anchor as default (top-left). Add some more buttons dotted around so that you can see that they scale correctly.
(2) Add the UserControl to a form in the construtor, after the InitializeComponent call.
(3) Run the form.
(4) Increase the form font size some way (eg click a form button).
All the controls within the usercontrol scale perfectly but the usercontrol itself doesn't. It's width and height are increased by way too much. Look at the margin now between the button at the bottom-right hand corner and the usercontrol.To correct the problem, the usercontrol must be added before the InitializeComponent call.If it wasn't possible for me to add the usercontrol before InitializeComponent, is there any way for me to correct the scaling?
View 2 Replies
Oct 30, 2009
I have a UserControl, with a TextBox and a databound property - Value.Value can be any object such as a Color, Array, Font etc.Any time the text changes, the property Value is changed as long as it is valid.Looking at the msdn article: How to: Apply the PropertyNameChanged Pattern , it says I should use the PropertyNameChanged Event patternfrom the control side.Now, If I have DataSourceUpdateMode = OnValidate, then I don't even need to apply this pattern. If, say. my Value property is bound to a colour field in a business object, then after I type red, in the textbox and tab to another field, then any other fields on the form, that bind to the same colour field, are updated immediately.
View 1 Replies
Jul 26, 2009
I am working on a wizard form framework that will allow me easily create wizard forms.I have a WizardForm form that has a panel on it. My plan is to dynamically load UserControls into this panel on the form.Each UserControl that is loaded onto the form panel must implement certain properties (allowNavigateNext, AllowNAvigate previous etc.). So I have created an interface to enforce that contract so that any custom user control can be used in the wizard as long as it implements that Interface. So far so good. created my first user control. I implemented the interface. All was good.I went to do the second user control and I realized that this second user control would have the EXACT SAME implementation of the interface as the first User Control. So...I thought...aha...duplicated code...how can I get rid of that.
View 3 Replies
Jan 28, 2011
Is there a way of stopping the main page waiting for a usercontrol to load before it can finish loading?
I have a usercontrolthat has to do a lot of DB calls which can take a few seconds making the page slow to load. Ideally I'd like the main page to load straight away and then the usercontrol content appear when it is ready.
View 4 Replies
Dec 29, 2009
I have a simple windows Forms application where in I have a usercontrol called "MyControl" derived from PictureBox.
In this MyControl, I have the following code :
Sub New()
MyBase.New()
Me.BackgroundImage = My.Resources.MyImage 'This is a project resource image
End Sub
Now when I drag and drop this MyControl into a form, I get the image and also those stuff. But the problem is that the BackgroundImage is being copied into the Form's local .resx file.So when I look into the form.designer file, I find the following :
Me.MyControl1.BackgroundImage = CType(resources.GetObject("MyControl1.BackgroundImage"), System.Drawing.Image)
This is a problem and also when I try to change the image in the control, it does not get reflected in the form's control instance.
View 3 Replies
May 25, 2011
My main form has two panels, left docked and right docked. The right side panel has two child panels with top dock and bottom dock settings. The usercontrol is added to the right side top panel. My usercontrol has a panel and a label. The panel is anchored on all 4 sides, the label is anchored on all except the bottom. At runtime I create this usercontrol and set it to dockstyle=fill and then I add it to my top right panel.
With everything set to "fill" I expect that when I add my usercontrol to the panel it will take on the appropriate width and height and pass that info to the child controls (labels) inside of my usercontrol. My problem is that this stretching of the size does not happen when I create my objects during the Load event on my usercontrol. Even though initializecomponent has ran for the usercontrol the panel inside of it (4 corners anchored) has not taken the x/y values of the available space. As a result my usercontrol shows up about 50% of the width I want.
[Code]...
View 1 Replies
Feb 16, 2011
Is there a more efficient/easier way changing the backcolor of a control when it has focus and lost focus? Let's say I've got 10 text boxes. Right now I would have 20 different events...10 for Enter event and 10 for Leave event. Of course, entering would change the back color to "green" and leaving would change it back to "white".
[Code]....
View 4 Replies
Aug 22, 2011
VB.NET Windows Forms Project, VS2010.I have a tabcontrol with several tabpages and on each tabpage there is a textbox. I want the focus (and insertion point) to go to the end of the text in the textbox when the tab is selected. If I make a junky project with the following code in each tab, it works fine:
Private Sub TabPage1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabPage1.Enter
With TextBox1
.SelectionStart = .Text.Length
.Select()
End With
End Sub
However, the same code is not working in my actual project. I am having trouble debugging, because if I step through, the breakpoints and IDE mean the focus events don't fire in the same order.
View 1 Replies
Apr 12, 2012
I'm developing an application in WinForms and I have 2 MDI children and I'd like to know the difference between Form.Focus and Form.BringToFront
I would like to know which one to use when clicking on a respective form's titlebar in order to have it pop up while I'm drag/dropping the form
If you are setting the child form mdiParent property after you are calling Form.Show then it messes up the focus of all the child forms so for me, drag/drop of MDI children inside an MDI parent won't focus the form upon Drag start, but only after MouseUp
View 2 Replies
May 16, 2012
I would like to show a Form without focus - PLUS - I would like to have 'Enable Application Framework' enabled on the My Project > Application form. Having 'Enable Application Framework' enabled allows trapping of unhandled exceptions project-wide.
I have added this to my code:
Protected Overrides ReadOnly Property ShowWithoutActivation() As Boolean
Get
Return True
[Code].....
View 8 Replies
Aug 4, 2010
I have a list of textboxs that are binded to a database.
When a user starts to type in one of these textboxs I draw a listbox right under that textbox that shows a list of other items in the field that start with the same keys.
IE, the user types in "Ni" and the list box will have "Nick" and "Nicholas" and so on...
That all works great but when I hit tab I want the next textbox to get focus and the listbox to hide.
If I just wait for the textbox to lose focus you can't do anything with the listbox because DOH the textbox just lost focus and the lsitbox hides.
This has led me in a circle of I'll try this and I'll try that for a while now.
I have listbox.tabstop set to false.
I've tried to manually set focus to the next textbox but the problem is that the listbox gets the focus that instant and all the gotfocus lostfocus code for the textbox is ignored.
I can't out right ignore the listbox getting focus.
View 6 Replies
Apr 15, 2012
In my WPF application I have a notification window that appears at the top right for 3 seconds and closes. Just a normal notification window.But when it appears, it takes the focus away from any window that was active.For example, if I'm typing in Chrome and the window appears, chrome looses focus and my typing is halted.The notification window is set to top most so that it will appear on top of other windows, but how do I go about stopping it from stealing the focus of the user?
View 1 Replies
Mar 21, 2012
I have a textbox on a form that when it loses focus it updates other text boxes on the form. But before it updates the other textboxes I check the input value in the textbox lostfocus event if it is undesired I return focus to the the textbox and alert the the user with a msgbox. However where my problem is, is that when the cancel button is clicked I don't care what the input in the textbox is because the changes are being canceled but if the value is undesired the it keeps returning focus to the textbox instead of canceling the changes. Is there a way to see what control was clicked on before or in the lost focus event? Can't seem to figure it out tried enter and leave events but no luck!
So for example something like this...
Code:
Private Sub TextBox1_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus
If Control that was clicked <> btnCancel then
[Code].....
View 2 Replies
Feb 14, 2010
I have a Visual Basic .Net form (launches after the splash screen tests database connectivity) and it is not focusing above other existing windows on launch. How do I get it to focus above all existing windows and Windows Explorer windows?
View 1 Replies
Sep 3, 2011
How do I autoscroll my richtextbox?
Form1_Load events;
How do I make it do this event occasionally? Like maybe every 5 launches, it does the event?
View 13 Replies
Dec 23, 2011
I have a thumbnail control where I am adding Images using openfiledialog and after adding it automatically scrolls down.
So I would like to stop scrolling the scrollbar and just append the Images.
I have tried using this code:
Thumbcontrol1.VerticalScroll.Value=0
It worked fine but the scrollbar is at the bottom and it shows me the first row of Images.
And this is my second attempt by doing this way:
I have just set the autoscroll property to false and it hides the scrollbars and I'm stuck with this so how do I scroll the remaining Images?
And Is there any other method to hide scrollbars and just scroll the Images using mouse? Or any other simpler way to get rid of this?
View 1 Replies
Jul 12, 2010
I have a VB.net form which has two webpages embedded. The webpages have a 5 second auto refresh built into the HTML header as the information is constantly changing.
The problem I have is when I pull up a secondary form, I lose focus to the 'Main' form everytime the webpage refreshes.
Is there any way to stop the webpages autorefreshing in the form and I will build in a refresh command into a timer I already have in place and then I can start and stop the refresh at will.
Unfortunatly I cannot amend the source code of the HTML as this is required for a different process elsewhere.
View 3 Replies
Jan 5, 2011
The code is listed below which hopefully illustrates what I'm trying to do:[code]....
View 12 Replies