C# "+" sign windows properties - c#

I have the class AppForm inherited Form with property AppIconForm (class).
I want at design time "+" sign appears on the edit IconForm property in the properties window and the child properties ( CloseIcon and MaximizedIcon ) appear. Thanks! :)
public partial class AppForm : Form
{
AppIconForm iconform = new AppIconForm();
public AppForm()
{
InitializeComponent();
}
public AppIconForm IconForm
{
get { return iconform; }
set { iconform = value; }
}
}
//the code of AppIconForm class
public class AppIconForm
{
Icon closeicon;
Icon maximizeicon;
public Icon CloseIcon
{
get { return closeicon; }
set { closeicon = value; }
}
public Icon MaximizeIcon
{
get { return maximizeicon; }
set { maximizeicon = value; }
}
}

Use BrowsableAttribute
[Browsable]
public Icon CloseIcon
{
get { return closeicon; }
set { closeicon = value; }
}

Related

Get info about something itself

I have this mistery:
public class UIWindow : Control
{
public PythonDictionary Variables;
public PythonTuple Children
{
get
{
if(Variables.has_key("children"))
return (PythonTuple)Variables["children"];
return null;
}
}
public UIWindow(PythonDictionary variables)
{
Variables = variables;
LoadChildren(Children, this);
Tag = "window";
}
private void LoadChildren(PythonTuple children, Control parent)
{
--recursive loading
}
}
Then i want that a class gets information about itself
public class UIText : Control
{
private PythonDictionary Myself
{
get
{
}
}
public string Name
{
get { MySelf["name"]; }
set { Myself["name"]; }
}
public UIText(Control parent)
{
Parent = parent;
Tag = "text";
}
}
I already know that my info is type of pythontuple because the LoadChildren of UIWindow did load all children from pythontuples, but how do i have reference to myself?
private PythonDictionary Myself
{
get
{
}
}

How to change name of xaml attribute in C#?

I want to serialize objects of class to xaml format. However, all of the properties name of class are directly serialized and I can't change their name.
I've used the
[DataMember(Name = "NameToChange")]`
attribute, but this still not solve the problem.
Please help me on this.
Here is the class:
public partial class XObject
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public string AtName
{
get
{
return this.Name;
}
set
{
this.Name = value;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public string AtType
{
get
{
return this.m_TypeToken;
}
set
{
this.m_TypeToken = value;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public string AtSerialize
{
get
{
return this.m_SerializeToken;
}
set
{
this.m_SerializeToken = value;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<string> AtValue
{
get
{
return m_Values;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Dictionary<string, XObject> AtAttached
{
get
{
return m_AttachedAttributes;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public string AtDynamic
{
get
{
return m_DynamicValue;
}
}
public void UpdateToken()
{
AtSerialize = (true == HasAttribute(AttributeNameToken_Serialize)) ? GetAttribute(AttributeNameToken_Serialize) : null;
AtType = (true == HasAttribute(AttributeNameToken_Type)) ? GetAttribute(AttributeNameToken_Type) : null;
foreach (XObject member in this)
{
member.UpdateToken();
}
}
private string m_TypeToken = null;
private string m_SerializeToken = null;
}

Populating combobox with two different objects

I want to populate a combobox with two different objects using an interface. This is what I currently got. This works but now I would like to have a display member and value member for each object, how would I do so?
In Controller.cs
public List<IMusic> Populate()
{
List<IMusic> newList = new List<IMusic>();
foreach(Track t in tr.GetAllTracks()){
newList.Add(t);
}
foreach (Artist a in ar.GetAllArtists())
{
newList.Add(a);
}
return newList;
}
IMusic.cs
interface IMusic
{
}
The combobox with DataSource:
cBMainScreen_Search.DataSource = controller.Populate();
GetAllTracks() :
public List<Track> GetAllTracks()
{
return db.Track.ToList();
}
GetAllArtists() :
public List<Artist> GetAllArtists()
{
return db.Artist.ToList();
}
Just setup some properties in your interface:
interface IMusic
{
string Display { get; set; }
string Value { get; set; }
}
Then in your Track class (which should implement IMusic):
public string Display
{
get
{
return this.TrackName;
}
set
{
this.TrackName= value;
}
}
public string Value
{
get
{
return this.TrackID;
}
set
{
this.TrackID= value;
}
}
And in your Artist class (also implements IMusic):
public string Display
{
get
{
return this.ArtistName;
}
set
{
this.ArtistName= value;
}
}
public string Value
{
get
{
return this.AritstID;
}
set
{
this.AritstID= value;
}
}

Disable editing child controls of custom DevComponents.DotNetBar control

I have created a new Custom Control inheriting from Bar control of DevComponents.DotNetBar controls. Next, I have created a new dock tab in it and have added my other controls to it.
After I compile my Custom Control and add my created Custom Control in a new Windows Form, Dock Tab Controls are editable at design time.
I don't want that anybody can edit these controls (Dock Tab Controls) in design time. How can I disable editing the controls at design time from the form (not the same as editing the control itself)?
public partial class barFloorsGrouping : Bar
{
public barFloorsGrouping()
{
InitializeComponent();
}
[ReadOnly(true)]
public new System.Windows.Forms.AccessibleRole AccessibleRole
{
get { return base.AccessibleRole; }
private set { base.AccessibleRole = System.Windows.Forms.AccessibleRole.ToolBar; }
}
[Browsable(false), ReadOnly(true)]
public new bool AlwaysDisplayDockTab
{
get { return base.AlwaysDisplayDockTab; }
private set { base.AlwaysDisplayDockTab = true; }
}
[Browsable(false), ReadOnly(true)]
public new bool AlwaysDisplayKeyAccelerators
{
get { return base.AlwaysDisplayKeyAccelerators; }
private set { base.AlwaysDisplayKeyAccelerators = true; }
}
[ReadOnly(true)]
public new bool AntiAlias
{
get { return base.AntiAlias; }
private set { base.AntiAlias = true; }
}
[Browsable(false), ReadOnly(true)]
public new bool AutoCreateCaptionMenu
{
get { return base.AutoCreateCaptionMenu; }
}
[ReadOnly(true)]
public new bool AutoHide
{
get { return base.AutoHide; }
}
[Browsable(false), ReadOnly(true)]
public new bool AutoHideTabTextAlwaysVisible
{
get { return base.AutoHideTabTextAlwaysVisible; }
}
[Browsable(false), ReadOnly(true)]
public new bool AutoSyncBarCaption
{
get { return base.AutoSyncBarCaption; }
private set { base.AutoSyncBarCaption = true; }
}
[Browsable(false), ReadOnly(true)]
public new eBarType BarType
{
get { return base.BarType; }
private set { base.BarType = eBarType.DockWindow; }
}
[ReadOnly(true)]
public new bool CanAutoHide
{
get { return base.CanAutoHide; }
}
[ReadOnly(true)]
public new bool CanDockTab
{
get { return base.CanDockTab; }
private set { base.CanDockTab = false; }
}
[ReadOnly(true)]
public new bool CanUndock
{
get { return base.CanUndock; }
private set { base.CanUndock = false; }
}
[Browsable(false), ReadOnly(true)]
public new bool CloseSingleTab
{
get { return base.CloseSingleTab; }
}
[Browsable(false), ReadOnly(true)]
public new bool DisplayMoreItemsOnMenu
{
get { return base.DisplayMoreItemsOnMenu; }
private set { base.DisplayMoreItemsOnMenu = true; }
}
[ReadOnly(true)]
public new DockStyle Dock
{
get { return base.Dock; }
}
[Browsable(false), ReadOnly(true)]
public new bool DockTabCloseButtonVisible
{
get { return base.DockTabCloseButtonVisible; }
}
[Browsable(false), ReadOnly(true)]
public new bool FadeEffect
{
get { return base.FadeEffect; }
private set { base.FadeEffect = true; }
}
[Browsable(false), ReadOnly(true)]
public new eGrabHandleStyle GrabHandleStyle
{
get { return base.GrabHandleStyle; }
private set { base.GrabHandleStyle = eGrabHandleStyle.Caption; }
}
[Browsable(false), ReadOnly(true)]
public new eLayoutType LayoutType
{
get { return base.LayoutType; }
private set { base.LayoutType = eLayoutType.DockContainer; }
}
[Browsable(false), ReadOnly(true)]
public new bool MenuBar
{
get { return base.MenuBar; }
}
[Browsable(false), ReadOnly(true)]
public new bool TabNavigation
{
get { return base.TabNavigation; }
private set { base.TabNavigation = true; }
}
[Browsable(false), ReadOnly(true)]
public new bool WrapItemsDock
{
get { return base.WrapItemsDock; }
private set { base.WrapItemsDock = true; }
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
}
You must extend the design mode behavior by using ParentControlDesigner Class. ParentControlDesigner Class provides a base class for designers of controls that can contain child controls.
So, for achieve to your Goal, you must implement design-time services for a component by DesignerAttribute as the following (Just add below code before the written class):
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]
public partial class barFloorsGrouping : Bar
{
...
}
EDIT: As always I work in asp.net and webforms... This answer is for WebForms
You would need to override the GetDesignTimeHtml of the WebControl.
see MSDN docs
It sounds to me like you haven't done a lot of server control creation so you are in for a lot of fun...

What is the proper way to handle an array of one class in another class?

Here are two simple classes to illustrate my question:
class Widget
{
private int _widgetID;
public int WidgetID
{
get { return _widgetID; }
set { _widgetID = value; }
}
private int _categoryID;
public int CategoryID
{
get { return _categoryID; }
set { _categoryID = value; }
}
private string _widgetName;
public string WidgetName
{
get { return _widgetName; }
set { _widgetName = value; }
}
}
And them the second class:
class WidgetCategory
{
private int _widgetCategoryID;
public int WidgetCategoryID
{
get { return _widgetCategoryID; }
set { _widgetCategoryID = value; }
}
private Widget[] _widgets;
public Widget[] Widgets
{
get { return _widgets; }
set { _widgets = value; }
}
private string _widgetCategoryName;
public string WidgetCategoryName
{
get { return _widgetCategoryName; }
set { _widgetCategoryName = value; }
}
}
How would I handle this situation in the most efficient way?
Also, so you know, I will need to nest other classes the same way below the Widget class.
You should create a read-only property of type System.Collections.ObjectModel.Collection<Widget>.
Collection properties should be read only
Use Collection<T>

Categories

Resources