<newbie> need a bit help on this code

J

Jeff

Hey

..NET 2.0
VS2005

I've created a TabControl based on this example:
http://www.codeproject.com/cs/miscctrl/closabletabcontrolpage.asp

I'm trying to use the PreRemoveTabPage event in the form (the form which
contain the TabControlEx):

I've tryed to implement the PreRemoveTabPage event like this (this code is
from the form), but it's never triggered when a tabpage is closed:
private void PreRemoveTabPage()
{
Debug.Write("hello world");
}

what am I doing wrong here?

Jeff
 
P

Peter Duniho

Jeff said:
I've created a TabControl based on this example:
http://www.codeproject.com/cs/miscctrl/closabletabcontrolpage.asp

I'm trying to use the PreRemoveTabPage event in the form (the form which
contain the TabControlEx):

I've tryed to implement the PreRemoveTabPage event like this (this code is
from the form), but it's never triggered when a tabpage is closed:
private void PreRemoveTabPage()
{
Debug.Write("hello world");
}

what am I doing wrong here?

You didn't post enough code for anyone to know for sure. But the first
question is: did you actually add (subscribe) that method to the event?

Though, upon looking at the page you referenced, it appears that
PreRemoveTabPage is not an event after all. It's a plain delegate. But
still, you need to assign your method to the delegate for it to be called.

One other thing: the delegate type returns a bool, while your method
returns void. You won't be able to assign your method to the delegate
until you fix the return type to match the delegate.

Pete
 
N

Nicholas Paldino [.NET/C# MVP]

Jeff,

I see a number of things wrong with the example code that is on the site
that you referenced. First, the code is exposing the delegate as a plain
delegate, and not an event. Second, the CloseTab method is the only thing
that fires the event. It should really be fired at a lower level, so that
it is handled everywhere.

Can you post your code? That would make it easier to figure out what
the problem is. The code for the form and the control, please (unless the
control code is the same as the code in the link).
 
M

Mark Peters

I've tryed to implement the PreRemoveTabPage event like this (this code is
from the form), but it's never triggered when a tabpage is closed:
private void PreRemoveTabPage()
{
Debug.Write("hello world");

}

what am I doing wrong here?
You need to add your method to the control's delegate similar to the
following:

tabControl1.PreRemoveTabPage += PreRemoveTabPage;

Note that the delegate is defined as follows:
public delegate bool PreRemoveTab(int indx);

So your method needs to be defined the same:
private bool PreRemoveTabPage(int x)
{
Debug.Write("hello world");
return true;
}
 
J

Jeff

Here is the code from the form:

The PreRemoveTabPage event isn't triggered. This is all the code I've done
on this form.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace minTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void PreRemoveTabPage()
{
Debug.Write("hello world");
}

}
}
 
N

Nicholas Paldino [.NET/C# MVP]

Jeff,

You have to attach the PreRemoveTabPage to the delegate exposed on the
control:

tabControlEx.PreRemoveTabPage += PreRemoveTabPage;

You will have to change your PreRemoveTabPage method to take an integer,
to conform to the delegate signature.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top