C# - Set Focus To A Deeply Nested Control In Windows Forms?

Jul 19, 2011

I have a main form that contains a vertical SplitContainer.Inside the SplitContainer's left panel, I have a TreeView control.Inside the SplitContainer's right panel, I have another SplitContainer (this one horizontal). This container is fixed, with headings above the split and a Panel control below it.I dynamically load my own user controls into the Panel control whenever the tree view changes.

Most of the user controls that are dynamically loaded have a DataGridView that should receive focus when the control is initialized. Sometimes this grid is on the UserControl surface directly; sometimes it's in a GroupBox; etc.What is the best way to programmatically set focus on the DataGridView control, given that it may placed within a variable number of control containers? I've tried the obvious - .Select, .Focus, .ActiveControl, etc. None of these seem to work - the TreeView item that I selected is still highlighted, and even though a record is selected in the DataGridView, it doesn't have focus.

Here's the code where I add the user control within the main form:

Private Sub LoadRightPanel(ByVal section As String, ByVal moduleName As String)
Heading.Text = String.Empty
SuspendLayout()
RightPanel.Controls.Clear()

[code]....

View 1 Replies


ADVERTISEMENT

Forms :: Changing The Backcolor Of A Control When It Has Focus And Lost Focus?

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

Can't Set Focus On A Windows Forms Textbox?

Jun 9, 2011

I can't seem to get input focus on a textbox when a tab page first comes up (I'm using Windows Forms, VB.NET 3.5). I have a textbox on a panel on a tab page, and I want the focus to be on the textbox when the tab page comes up. I want the user to be able to start typing immediately in the focused textbox without having to click on the textbox. I have tab stops set in the order I want and the textbox is the first tab stop. The tab stops work except that when the tab page comes up the focus is not on the textbox, i.e. the one that's first in the tab order.

In the Enter event handler of the tab page I call the Focus method of the text box, but it returns False and does nothing, no error messages. I know I can access the text box because at the same point in the code I can set the text of the text box.If it matters, the layout of the tab page is a little complicated:[URL]..I want to set the focus on TextBox1.

What's the best way to get the focus on the desired textbox? If setting focus is the best way, why is the textbox.Focus() method failing?

View 5 Replies

Forms :: Restore A Windows Form Which Is Minimized And Has Lost Focus?

Dec 2, 2009

I have created an app which has a timer control which, when activated and meets a certain criteria, launches a second form with an alert for the user to review and action. this works just fine. Except.... when the main app is minimised and has lost focus, instead of launching the second form to a normal windows state it opens and sits in a minimized state itself and just flashes. How can I get the the second form to restore to a normal windows state?I have tried form2.focus and tried the windowsstate=normal etc but I'm still barking up the wrong tree.

View 2 Replies

Windows Forms: Unable To Click To Focus A MaskedTextBox In A Non TopLevel Form

May 20, 2010

I've got a Child form being shown with it's TopLevel property set to False and I am unable to click a MaskedTextBox control that it contains (in order to bring focus to it). I can bring focus to it by using TAB on the keyboard though.

The child form contains other regular TextBox controls and these I can click to focus with no problems, although they also exhibit some odd behavior: for example if I've got a value in the Textbox and I try to drag-click from the end of the string to the beginning, nothing happens. In fact I can't use my mouse to move the cursor inside the TextBox's text at all (although they keyboard arrow keys work).I'm not too worried about the odd TextBox behavior, but why can't I activate my MaskedTextBox by clicking on it?

Below is the code that shows the form:

Dim newReportForm As New Form
Dim formName As String
Dim FullTypeName As String
Dim FormInstanceType As Type

[code].....

View 3 Replies

Setting Focus On Nested Custom Controls?

Jan 10, 2011

I have a nested custom control that I need to set focus on. I have it all internally wired up to automatically set the focus when the form loads, but when it comes up on screen, the designated accept button for the parent form is in focus instead. Even when is disassociate the accept button it still does not set correctly. How can I ensure my desired control gets focus.

View 2 Replies

Implicit Conversions From 'System.Windows.Forms.Control' To 'System.Windows.Forms.Webbrowser'

Sep 8, 2010

I have the code which checks if there is a selected tab

Private Function GetBrowser() As WebBrowser
If TabControl1.SelectedTab IsNot Nothing Then
For Each c As Control In TabControl1.SelectedTab.Controls
If TypeOf (c) Is WebBrowser Then
Return c

[Code]...

View 2 Replies

Forms :: Form Losing Focus - Keeps Loosing Focus ?

Nov 26, 2009

I have two forms in an application. One is he background and then I show another keypad form called with the show() method (not showDialog) because I need to perform some validations on btn click.

The kepad has 10 buttons and an Enter Button. The problem is that the form keeps loosing focus (I checked this with a messagebox which keeps poping up once for focus=true and again for focus=false, it continuously keeps losing and gaining focus) so it does not process any keypress events untill i click somewhere on the form. I tried using me.focus() in form load event but to no avail. The forms TopMost property is also set to true.

View 5 Replies

Lost Focus Event, What Control Is Getting Focus?

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

C# - Windows Forms Separator Control?

May 16, 2011

Where in VS2010 can I find a horizontal separator control, as can be found in Outlook settings (screenshots below)?[URL]..

View 3 Replies

Windows Forms Timer Control

Jun 30, 2011

Whatever project I'm making, I always encounter a problem with a Windows Forms Timer control, I guess I just make a little mistake somewhere... So I thought I'd post it here and hopefully someone here can explain what I'm doing wrong.

[Code]....

View 3 Replies

Add Images To Listbox Control Of Windows Forms?

Jan 3, 2011

is it possible to add images to listbox control of windows forms..

if I do it anyhow using items.add method one item at a time then how to add items valuemember to items ..

View 6 Replies

C# - Recommendations For A Hex Viewer Control For Windows.Forms?

Mar 25, 2010

I need ability to display content in Hex View, like this from WinHex

Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
00000000 EF BB BF 0D 0A 4D 69 63 72 6F 73 6F 66 74 20 56 ..Microsoft V
00000010 69 73 75 61 6C 20 53 74 75 64 69 6F 20 53 6F 6C isual Studio Sol

[code]....

View 3 Replies

Custom Grid Control Using GDI + For Windows Forms?

Nov 4, 2009

I have to design a custom "log grid" control to use in another of my projects.Up front, I am new to vb.net 2008. I have used VB6 for years and I am trying to learn how to resove the differences as I go. But I need help.

This log grid contains 96 columns and 4 rows.I tried using the TableLayoutPanel and a Panel per cell but found the control to slow to paint. That's 384 discreet controls.I am now trying a usercontrol with a panel and GDI+ to create the grid. I've created a collection for the columns and a collection for the rows. So far so good. My mouse clicks raise the correct events per cell.

I now need to indicate which column the mouse is over. This is the problem. The column must be highlighted by a vertical bar from the top of the column to the bottom. It must also be transparent. I need to see the gridlines under the highlight. I've tried using region using the following code. (myRegion is declared Private MyRegion as Region at module level for persistance)

[Code]...

View 4 Replies

Embedding A Windows Forms User Control

Mar 16, 2009

I can't get this to work get a funny icon in the top left corner of the are where the user control is suppose to appear, here is my html markup.[code]

View 4 Replies

'image' Is Not A Member Of 'System.Windows.Forms.Control'

Oct 18, 2010

I have several pictureboxes in my form with names as "stop0", "stop1", "stop2" ... upto a the number of checked items in my checklistbox. My aim is to use a for-next function so that the program should use for all these pictureboxes a specific image. here is the code I made so far:

Dim a As String = selectedbutton.Replace(" ", "_") & "_"
Dim c As String = ""
For n = 0 To chklstStops.CheckedItems.Count

[Code]......

View 6 Replies

Control Can Exercise Over A System.Windows.Forms.FlowLayoutPanel?

Oct 23, 2009

I've been working for several days on a GUI where a lot of individual data elements need to be displayed side-by-side and wrap to the next line when they overflow; the goal is to not have to explicitly design an individual 'row' element with a set number of elements for this purpose. The FlowLayoutPanel seems great, except...

I need to be able to determine how many elements are on each line (dividing the width of the control by a predetermined value indicating width of child controls does not work); I need to be able to determine how many elements will be on each line (I may need to put 4 elements on line 1, then auto-wrap, then 8 elements on line 2, then auto-wrap, then as many elements as can fit on line 3 before autowrap, then 16 elements on line 4, etc); and finally I'd really like to put a 'line header' at the left margin and a 'line footer' at the right margin, where for example the line header contains a line number and the line footer contains the number of elements on that line.

View 6 Replies

Creating User Control - Reuse In Different Windows Forms ?

Apr 15, 2010

In my project i added a User Control so that i can reuse in different Windows forms.I designed and coded the UserControl1 according to my need and now i want to use it in Form2 but i cant understand how to do it?

View 2 Replies

IDE :: Windows Forms Control Leave Event Fires More Than Once?

Jul 11, 2009

The leave event fires twice in this example. Tab order for the form controls is set to combobox1, button1, button3 Private Sub ComboBox1_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.Leave

[Code]...

if I enter 'A' in the combobox1 then combobox1 leave event will fire twice any other entry is Ok since the next control to get focus is button2 (in the normal tab order).It seems that if I try to skip the next control (based on the tab order set for the form), the leave event fires twice.

View 2 Replies

Se IE9 Rendering Engine For The Windows Forms WebBrowser Control

Apr 14, 2012

I can't seem to find a way to use the IE9 rendering engine in the WebBrowser control, instead of the IE7 rendering engine, using Visual Studio 2010 and Windows Forms.

View 2 Replies

SelectedIndex Is Not A Member Of System.Windows.Forms.Control

Mar 8, 2010

I am trying to read values from textbox controls and combobox controls on a form. Reading the values from textbox controls is working fine but I cannot read from the 3 combo boxes. Here is some simplified code of what I am trying to do.

[Code]....

View 5 Replies

VS 2008 String To System.Windows.Forms.Control?

Dec 9, 2009

I got an error that i cant convert string to System.Windows.Forms.Control and i was wondering how could i do it this is the code that contains error:

If ResultRichTextBox.Contains("Text") Then

View 2 Replies

VS 2008 User Control Complication With Windows Forms?

Nov 24, 2010

I have a program that I am creating in a windows form to track information about computers that I build for each project I do. The way I have my form layout is two buttons on the top of the form(1 for adding a computer and the 2nd to remove a computer) I then have a Tab window where when I want to add a computer I use the "Add button" click event to create a new tab and add a user control "Computer" that I created that contains all of the default fields that I desire (i.e. serial numbers os type, product key etc.) The "Computer" user control also contains two buttons (1 for adding a PC Card and the 2nd to remove a PC Card) The PC Card is another user control that I have created that has all of the desired fields I require for PC Cards. I am able to add new computers with no problem and name the tab

Dim b As New Computer
Dim x As String = Me.TabEquip.TabCount - 2
Dim tab As New TabPage("Computer" + x)

[code].....

View 2 Replies

Windows Forms Control Layout For Maximized View?

Jul 15, 2009

I am using Visual Basic Express 2005. I am opening the startup form of my application in "Maximized" view. In the form designer, I am setting the anchor properties of the various controls that I have on the form so that they are located where I want them to be located when the Form loads.

I was wondering, if there was a way such that the form in my designer would be of the same size as the Maximized form? As of now I am dragging and resizing the edges of the Form in the Designer view to make it bigger..

View 7 Replies

Winforms - Where And When Is InitializeComponent Called In Windows Forms Control

Jun 25, 2009

In C# Windows Forms, a user control's InitializeComponent is called from the form's/control's constructor. When I create same scenario in VB.NET I don't get a constructor, and I can't locate a place where InitializeComponent is called.I need to call my code between InitializeComponent and when the control's Load event is raised, preferably still in the control's constructor. How do I do this in VB.NET?

View 2 Replies

Bring Up PDF Embedded In Windows.forms.webbrowser Control In VISTA?

Nov 26, 2009

XP WEBBROWSER-CONTROL: brings up PDF embedded in webbrowser control, as desired.XP IE7: Behaves the same if you manually navigate to URL, as desired.VISTA WEBBROWSER-CONTROL: brings up PDF by separately launching Acrobat, won't embed in webbrowser control. Not desired.Vista IE7: embeds PDF properly if you navigate to same URL, as desired.I am using Acrobat 9, where there is a preference setting under Internet to bring up PDF embedded in browser -- works fine directly in IE7, but not in webbrowser control.

View 2 Replies

Data Binding - DataList Control In Windows Application Forms?

Jun 6, 2010

I am upgrading my application from vb6 to vb.net.I used to populate my data in datalist control in vb6 forms. I am not finding it in vb.net windows form application. Which one control is the equivalent to it?

How can i list my data in that control?

just like: I had a table with data like id, name

I want the name should be the displayed column and id the bound column? how can i do that

View 1 Replies

Dock A Control Inside A Panel At Runtime On Windows Forms?

Jul 27, 2009

I am designing a simple user interface using winforms. In the designer I have a panel on the form and would like to add a datagridview control into the panel at runtime and set the dock property of the datagridview to 'Fill' so that it fills the panel.

I am struggling to do this and following code is not working out for me:

Dim MyDataGridview as New DataGridView()
MyDataGridView.Dock = DockStyle.Fill
Me.MyPanel.Controls.Add(MyDataGridview)

I don't get an error but the datagridview isn't visible. It gets added 'behind' the panel and so I tried using .SendToBack() and .BringToFront() methods thinking that the panel was hiding the datagridview but this doesn't seem to work either. At any rate, it seems like the datagridview is being added to the form but just not docked within the panel

View 4 Replies

IDE :: Disable The Context Menu For Webbrowser Control In Windows Forms Using C#?

Sep 9, 2005

disabling the context menu for webbrowser control in Windows forms using c#.

View 2 Replies

Require That A Class Is A Windows.Forms.Control And Implements An Interface?

Nov 29, 2011

I'm not sure that I'm doing the right thing here..I'm writing a user control that's supposed to be (fairly) generic. It's a bit like a modified email client specifically tailored to some of the internal things we do.

The view is composed of two main pieces, a message list and a viewer. I need this viewer to be interchangeable, so if someone wants a different style of view they can simply handle an event and change a property. My original idea was to just have an INoteViewer, but since I'm adding it to my form I also need to guarantee that this object is a Windows.Forms.Control of some sort.

Should I continue along these lines and maybe raise an ArgumentException if I can't cast it to INoteViewer, or should I go a different direction and create a class that inherits from Windows.Forms.Control?

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved