First if a class instance is continuously being created over and over again does this inhibit performance Vs's say using a static class? For instance I have a class that helps output a string of the current font used and it gets fired every single time someone types a letter in the richtextbox like so
private void Update_Font_Lbl()
{
//new instance created
CGetRTBFontString rtbs = new CGetRTBFontString();
rtbs.Set_Font_Object = (this.tbctrl_main.SelectedTab.Tag as RichTextBox);
this.tlstrp_lbl_font.Text = rtbs.Return_Font_String();
}
private void rtb_selection_changed(object sender, EventArgs e)
{
Update_Font_Lbl();
}
Does this make any difference?
Second I hope I haven't become too obsessive but I've even been creating classes for simple things like a font dialog like so
abstract class CFontChangePrompt<T>
{
protected abstract Font Get_Set_Font
{
set;
}
public abstract T Font_Change_Object { get; set; }
public void Set_Font_To_Object_With_Dialog()
{
using (FontDialog fd = new FontDialog())
{
if (fd.ShowDialog() == DialogResult.OK)
{
this.Get_Set_Font = fd.Font;
}
}
}
}
class CFontChangeRTB : CFontChangePrompt<RichTextBox>
{
public override RichTextBox Font_Change_Object
{
get;
set;
}
protected override Font Get_Set_Font
{
set
{ this.Font_Change_Object.SelectionFont = value; }
}
}
}
What the above code allows is the changing of a font type for multiple objects types in classes for instance a Richtextbox but you could create another class for changing the font for a menu or a label etc. etc.
Am I being obsessive using classes for even simpler things like this or is this good code?
LAST BUT NEAT LEAST For some things that will be used the same way over and over again in a particular way that can't change I figured static classes were better for example in my creation of a new tab I use
public static class CTabMethods
{
private static int tab_num = 2;
private static int Increment_Tab_Num
{
set { tab_num += value; }
}
public static TabPage Return_RTB_Tab_Object()
{
var tab = Create_Default_Tab_Page();
var rtb = Create_Default_RTB();
tab.Controls.Add(rtb);
tab.Tag = rtb;
Increment_Tab_Num = 1;
return tab;
}
private static TabPage Create_Default_Tab_Page()
{
TabPage t = new TabPage
{
BackColor = SystemColors.Control,
Location = new Point(4, 22),
Padding = new Padding(3),
Size = new Size(744, 465),
Name = "tb" + tab_num.ToString(),
Text = "tb" + tab_num.ToString(),
TabIndex = 0
};
return t;
}
public static void Close_Currently_Selected_Tab_Page(TabControl ctrl)
{
if (ctrl.TabCount > 1)
{
ctrl.SelectedTab.Dispose();
}
}
private static RichTextBox Create_Default_RTB()
{
RichTextBox r = new RichTextBox
{
Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right),
Location = new Point(6, 6),
Size = new Size(732, 453),
TabIndex = 2,
Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))),
Name = "rtb" + tab_num.ToString()
};
return r;
}
}
Is this a proper time to use static classes?
THANKS IN ADVANCE GUYS

New Topic/Question
Reply



MultiQuote






|