In a nut shell, I am trying to inherit System.Windows.Forums.TabControl & ...TabPage. I order to add a custom prop field. Now all indications point to it working. (IntelliSence displays custom prop, and the form designer indicates the inherited control is correctly being used)
How ever <tabcontrolername>.SelectedTab.<customprop> is always blank (null).
In order to spare you all the ins and outs, I created a generic project describing what I'm trying to do. In the sample the custom prop is a string (to keep it simple), however in the real app it's an instance of a custom struct.
So, any ideas as to what I'm doing wrong?
Base form code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TabStorage
{
public partial class fmMain : Form
{
public fmMain()
{
InitializeComponent();
}
private void btNew_Click(object sender, EventArgs e)
{
NTabPage np = new NTabPage();
np.Text = "New Tab";
np.PageMode = "Custom Tab Prop String";
tcTabControl.TabPages.Add(np);
np = null;
}
private void btInfo_Click(object sender, EventArgs e)
{
MessageBox.Show(tcTabControl.SelectedTab.PageMode);
}
}
}
Win Forms Designer code:
namespace TabStorage
{
partial class fmMain
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btNew = new System.Windows.Forms.Button();
this.btInfo = new System.Windows.Forms.Button();
this.tcTabControl = new TabStorage.NTabControl();
this.SuspendLayout();
//
// btNew
//
this.btNew.Location = new System.Drawing.Point(0, 12);
this.btNew.Name = "btNew";
this.btNew.Size = new System.Drawing.Size(75, 23);
this.btNew.TabIndex = 0;
this.btNew.Text = "New Tab";
this.btNew.UseVisualStyleBackColor = true;
this.btNew.Click += new System.EventHandler(this.btNew_Click);
//
// btInfo
//
this.btInfo.Location = new System.Drawing.Point(0, 41);
this.btInfo.Name = "btInfo";
this.btInfo.Size = new System.Drawing.Size(75, 23);
this.btInfo.TabIndex = 1;
this.btInfo.Text = "Get Info";
this.btInfo.UseVisualStyleBackColor = true;
this.btInfo.Click += new System.EventHandler(this.btInfo_Click);
//
// tcTabControl
//
this.tcTabControl.Location = new System.Drawing.Point(81, 12);
this.tcTabControl.Name = "tcTabControl";
this.tcTabControl.PageMode = null;
this.tcTabControl.SelectedIndex = 0;
this.tcTabControl.Size = new System.Drawing.Size(229, 328);
this.tcTabControl.TabIndex = 2;
//
// fmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(322, 352);
this.Controls.Add(this.tcTabControl);
this.Controls.Add(this.btInfo);
this.Controls.Add(this.btNew);
this.Name = "fmMain";
this.Text = "Tab Storage";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btNew;
private System.Windows.Forms.Button btInfo;
private NTabControl tcTabControl;
}
public class NTabControl : System.Windows.Forms.TabControl
{
private string m_PageMode;
private NTabPage m_TabPage = new NTabPage();
public string PageMode
{
get { return m_PageMode; }
set { m_PageMode = value; }
}
public new NTabPage SelectedTab
{
get { return m_TabPage; }
set { m_TabPage = value; }
}
}
public class NTabPage : System.Windows.Forms.TabPage
{
private string m_PageMode;
public string PageMode
{
get { return m_PageMode; }
set { m_PageMode = value; }
}
}
}
I hope you reported that comment so yw71 understands what actually is a comment that should be reported while getting a break from here for a couple of days. LOL
The feature seems entirely pointless and looking for a solution to a problem that doesn't exist, but I certainly wouldn't trust Wikipedia editors to have the best interests of truth and impartiality in mind when rallying against it. They're up there with Reddit moderators for doing what's in the best interest of them wielding the tiny bit of power they have in as obnoxious a way as possible. They more likely see AI as a threat to their little fiefdoms.
That was what you were referring here to here? The .x version numbers? LOL Those will still be happening. No idea why you would think that would change because they moved the whole number version ahead.
Question
KXM
I hit a wall...
In a nut shell, I am trying to inherit System.Windows.Forums.TabControl & ...TabPage. I order to add a custom prop field. Now all indications point to it working. (IntelliSence displays custom prop, and the form designer indicates the inherited control is correctly being used)
How ever <tabcontrolername>.SelectedTab.<customprop> is always blank (null).
In order to spare you all the ins and outs, I created a generic project describing what I'm trying to do. In the sample the custom prop is a string (to keep it simple), however in the real app it's an instance of a custom struct.
So, any ideas as to what I'm doing wrong?
Base form code:
Win Forms Designer code:
The full poroject in a zip.
TabStorage.zipFetching info...
Link to comment
https://www.neowin.net/forum/topic/442553-c-inherting-tabpage-tabcontrol/Share on other sites
4 answers to this question
Recommended Posts