.NET Framework - Problem with tab control event

Asked By Mark F.
07-Mar-07 07:43 PM
I have two tab controls (four tabpages each) and each tab control is in a
splitter panel (horiz orientation). I added a event handlers to handle the
selected tab event. The upper tab control works when every tab is selected.
The lower tab control only seems to work when the first three tabs are
selected, not the last.

Any ideas why?

Thanks,
Mark
SelectedIndexChanged
(1)
EventArgs
(1)
TabIndexChanged
(1)
Paint
(1)
  Jay Riggs replied...
09-Mar-07 04:09 PM
Mark,

I created a VS.NET 2003 WinForm project, added a panel and to the
panel a tab, a splitter (oriented as horizontally) and another tab.

I wired both tab controls to its SelectedIndexChanged event and on
clicking each TabPage in both tabs the event fired.

I then wired the TabIndexChanged event for both tabs and found that
this event didn't fire for any TabPage for either tab.  I'm not sure
why, perhaps I don't understand what the event is supposed to do
exactly.

For fun (or at least what passes for fun for me these days) I had both
tabs SelectedIndex property display when the SelectedIndexChanged
events fired.  I noticed that the SelectIndex was changing, yet
changing the index via a mouse click wasn't firing the TabIndexChanged
event.

I was going to post my project but saw that it would have been pretty
much illegible.  If you're not using the SelectedIndexChanged event
for your tab controls, perhaps that's you're solution.

-Jay
  Mark F. replied...
10-Mar-07 10:36 AM
Thanks Jay,

I simply wanted to display the current view (tabpage) on a statusbar pane.
private void viewsTabControl_SelectedIndexChanged(object sender, EventArgs
e)
{
sbrViewPane.Text = viewsTabControl.SelectedTab.Text;

// or ...,

// sbrViewPane.Text =
viewsTabControl.TabPages[viewsTabControl.SelectedIndex].Text;
}

I think that I found the trouble. One view is a picturebox control that
previews an image file if the user selects one. I used the OnPaint event to
draw text in the view if the user clicks the tab and no image is loaded (ie,
SelectedIndexChanged event fires normally for the preview tabpage. I still
don't know why this behavior is occurring however.

Mark
Create New Account
help
WinForms manually calling SelectedIndexChanged on combobox .NET Framework Hello, I'd like to force a call to the SelectedIndexChanged of a combo box from within a method. I tried to just call it like so: this.myComboBox.SelectedIndexChanged; but of course the event takes 2 parameters - object sender EventArgs e and not sure how to pass these paras from my method. Should I just make up fake ones to pass? Any help would be appreciated. G C# Discussions EventArgs (1) SelectedIndexChanged (1) SelectedIndexChange (1) Report (1) OP (1) SelectedIndex (1) WinForms (1) Eventhandler (1) GiJeet, You mvp@spam.guard.caspershouse.com GiJeet, at the time you're in the method, the SelectedIndexChanged event handler has already been called when it was set to whatever value it holds the time. You CAN actually call it yourself like this: this.comboBox1_SelectedIndexChanged(this.comboBox1, new EventArgs()); but remember that it's already been called once for the current value. The fact
it still happens I do not know what this means, thank you your help. {Name = "EventArgs" FullName = "System.EventArgs"} [System.RuntimeType]: {Name = "EventArgs" FullName = "System.EventArgs"} base {System.Reflection.MemberInfo}: {Name = "EventArgs" FullName = Assembly: {mscorlib, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089} AssemblyQualifiedName: "System EventArgs, mscorlib, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089" Attributes: Public | Serializable | BeforeFieldInit BaseType DeclaringMethod: 'e.GetType().DeclaringMethod' threw an exception of type 'System.InvalidOperationException' DeclaringType: null FullName: "System.EventArgs" GenericParameterAttributes: 'e.GetType().GenericParameterAttributes' threw an exception of type 'System.InvalidOperationException' GenericParameterPosition: 'e.GetType().GenericParameterPosition ReflectedType: null StructLayoutAttribute: {System.Runtime.InteropServices.StructLayoutAttribute} TypeHandle: {System.RuntimeTypeHandle} TypeInitializer: {Void .cctor()} UnderlyingSystemType: {Name = "EventArgs" FullName = "System.EventArgs"} ASP.NET Discussions ASP.NET (1) EventArgs (1) InvalidOperationException (1) RuntimeTypeHandle (1
marked with * below how would that / / Create a delegete public delegete void MyEventHandler(object sender, EventArgs e); / / Create an event member public event MyEventHandler MyEvent; / / Invoke the delegete within a method need to raise the event, as the following code demonstrates if(MyEvent ! = null) MyEvent((this, EventArgs.Empty) EventArgs e = new EventArgs(); if (handler ! = null) handler(this, e); C# Discussions NotImplementedException (1) Tell Tony Willem van Rumpt (1) EventHandler EventArgs (1) EventHandler (1) EventArgs (1) Class (1) Bit (1) Arne Arne Vajhøj (1) I do not see the * !?!? Arne mean something like this? - -- -- MyEvent = new MyEventHandler( (sender_, e_) = > { throw new NotImplementedException(); }); MyEvent.Invoke(this, EventArgs.Empty); - -- -- Or just. . . - -- -- if (MyEvent ! = null) { MyEvent.Invoke(this, EventArgs.Empty); } - -- -- In the book I read it says the following. How to raise an event
how could you programatically "click" on a button in a Form ? VB.NET Discussions System.EventArgs (1) EventArgs.Empty (1) EventArgs (1) Button1.Click (1) System.Object (1) SendKeys (1) Computer (1) Control (1) Hi Rob Click like: Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click ' Code block here when button is pressed End Sub . . .and if you a disabled button) and you don't have to worry about getting hold of valid EventArgs to pass to the "method" call. OK, for Click events they're pretty simple, but should be the Control / raising / the event, not the form / handling / it, so . . . Button1_Click( Button1, EventArgs.Empty ) . . . would be more correct. HTH, Phill W. Phill, Do what you want, I have