Edit my control from designer - c#

I created control which contains a label and a textbox next to it:
The hierarchy look like that:
Panel
->Panel
->TextBox
->Label
I want to be able to custom the it on designer like change the textbox and label size and the text of the textbox.
Is there a easier way to do it without the needs to add property for each datamember of each control and calculate the sizes?
I have this code right now:
public override string Text
{
set { this.PhoneLabel.Text = value; }
get { return this.PhoneLabel.Text; }
}
public Size SizePhone
{
set { PhoneTextBox.Size = value; }
get { return PhoneTextBox.Size; }
}
public Size SizeLabel
{
set { PhoneLabel.Size = value; }
get { return PhoneLabel.Size; }
}
public Point LocationLabel
{
set { PhoneLabel.Location = value; }
get { return PhoneLabel.Location; }
}
I want to change the size with the mouse like I design a form
Thank you

Related

C# UserControl with combobox

I created a UserControl with TextBox, Image and Label
In the properties of the usercontrol everything works great except the ComboBox, I can't load the datasource so that the client chooses the option it wants to give to the TextBox.
For example, let's suppose that the combobox has 3 options so that the TextBox only accepts the data input selected by the client
"only letters - only numbers - letters and numbers"
private Image image;
private string data;
[Category("Custom UI")]
public Image Image
{
get { return image; }
set {
image = value;
pictureBox.Image = value;
}
}
[Category("Custom UI")]
public string Data
{
get { return data; }
set {
data = value;
label.Text = value;
}
}
In the following image you can see that everything is going well except for the combobox, its data load is null
I want to load the combox with the 3 options outlined above, I don't know if what I'm doing is correct, please help
private ComboBox textOptions;
[Category("Custom UI")]
public ComboBox TextOptions
{
get { return textOptions; }
set
{
textOptions = value;
}
}

Adding custom cells in Xamarin

I have a UITableView which contains a prototype cell, with components added onto it in the storyboard, and referenced in my CustomCell.h & .m files, with the CustomCell.cs looking like this:
public partial class CustomCell : UITableViewCell
{
public CustomCell(IntPtr handle) : base(handle)
{
}
public UILabel Sender
{
get
{
return senderLabel;
}
set
{
senderLabel = value;
}
}
public UILabel Subject
{
get
{
return subjectLabel;
}
set
{
subjectLabel = value;
}
}
public UILabel Date
{
get
{
return timeLabel;
}
set
{
timeLabel = value;
}
}
public UILabel Preview
{
get
{
return previewLabel;
}
set
{
previewLabel = value;
}
}
public UILabel Initials
{
get
{
return initialsLabel;
}
set
{
initialsLabel = value;
}
}
}
This custom cell is then used in my table's source file, and its GetCell method, to try and add data to the table:
CustomCell cell = tableView.DequeueReusableCell("MailCell") as CustomCell;
cell.Sender.Text = TableItems[indexPath.Row].Sender;
cell.Subject.Text = TableItems[indexPath.Row].Subject;
cell.Preview.Text = TableItems[indexPath.Row].Preview;
cell.Date.Text = TableItems[indexPath.Row].Time;
cell.Initials.Text = "";
When you run the program and try and add the data to the table, it breaks on the second line of the GetCell method with a NullReferenceException, which implies that their is either no label in the cell, or that there is no cell to edit. My prototype's cell has an identifier of "MailCell", and I have tried making a full constructor in the class, which didn't work. I had previously programmatically added in the components into the table's cell's, and that worked perfectly and therefore I can be sure that my code to add the data to the source works as intended, and is not the problem. What else is there possible to test?
It breaks because it can not find an instance of you custom cell for the very first row.
DequeueReusableCell is looking for an instance if it can not find one it returns null
Change your code to:
CustomCell cell = tableView.DequeueReusableCell("MailCell") as CustomCell ?? new CustomCell();

Add another dropdown button to own devexpres PopupContainerEdit with same style behaviour

We've got custom PopupContainerEdit that inherits from DevExpress'es PopupContainerEdit. One of our custom features is another dropdown button (EditorButton with kind = ButtonPredefines.Glyph) that acts like the default one except, it opens different PopupContainerControl. Everything works as intended except button's style coloring. The button acts like default button - that means it doesn't support state coloring (checked/unchecked) when dropdown is visible/hidden. I couldn't find any custom draw event/method for EditorButton.
Is it possible to achieve such behaviour? If so, how?
#edit
Simple example of the above situation.
Default PopupContainerEdit looks like image A. When you click on the
button (triangle like), dropdown shows and button goes into checked
state.
Our PopupContainerEdit (that inherits from default) looks like
B.
C, D is coloring example when you hover the button.
E is checked state coloring for default button (it works like that by
DevExpress'es design).
F is our button behaviour - acts like normal button.
G is what we want - checked state coloring for our button
Our approach to create custom button:
string TheToolTipText = "The text";
string OurButtonTag = "TheButton";
Image TheIcon = new Image(); // just example ...
EditorButton customButton = new EditorButton();
customButton.Width = 16;
customButton.Image = TheIcon;
customButton.ToolTip = TheToolTipText;
customButton.Tag = OurButtonTag;
customButton.Kind = ButtonPredefines.Glyph;
this.Properties.Buttons.Add(customButton);
To be honest there's nothing more to show. We're not aware of any custom Draw event or similar things.
There are two properties in RepositoryItemPopupContainerEdit that are responsible for this behavior. Fisrt one is RepositoryItemPopupBase.ActionButtonIndex property. It's value specifying which editor button will open the editor's dropdown window. The second one is RepositoryItemPopupContainerEdit.PopupControl which sets the control to display in the popup window. So, by manipulating with this two properties, you can achieve the desired behavior.
Here is example:
0. RepositoryItemPopupContainerEdit descendant
Because you need to show two different PopupContainerControl
you can create additional properties for each of your controls in your custom RepositoryItem.
public class RepositoryItemCustomEdit1 : RepositoryItemPopupContainerEdit
{
#region Some default stuff for custom repository item (constructors, registration, etc).
static RepositoryItemCustomEdit1() { RegisterCustomEdit1(); }
public const string CustomEditName = "CustomEdit1";
public RepositoryItemCustomEdit1() { }
public override string EditorTypeName { get { return CustomEditName; } }
public static void RegisterCustomEdit1()
{
Image img = null;
EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(
CustomEditName,
typeof(CustomEdit1),
typeof(RepositoryItemCustomEdit1),
//For v13.2 you need to use custom ViewInfo class. So, here is CustomEdit1ViewInfo.
//For v15.1 you can use the base PopupContainerEditViewInfo.
typeof(CustomEdit1ViewInfo),
new ButtonEditPainter(),
true,
img));
}
#endregion
#region Hide base PopupContainerControl properties in designer.
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override PopupContainerControl PopupControl
{
get { return base.PopupControl; }
set { base.PopupControl = value; }
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override int ActionButtonIndex
{
get { return base.ActionButtonIndex; }
set { base.ActionButtonIndex = value; }
}
#region
#region First PopupContainerControl properties
public int DefaultActionButtonIndex { get; set; }
public PopupContainerControl DefaultPopupControl { get; set; }
#endregion
#region Another PopupContainerControl properties
public int DifferentActionButtonIndex { get; set; }
public PopupContainerControl DifferentPopupControl { get; set; }
#endregion
public override void Assign(RepositoryItem item)
{
BeginUpdate();
try
{
base.Assign(item);
RepositoryItemCustomEdit1 source = item as RepositoryItemCustomEdit1;
if (source == null) return;
DefaultActionButtonIndex = source.DefaultActionButtonIndex;
DefaultPopupControl = source.DefaultPopupControl;
DifferentPopupControl = source.DifferentPopupControl;
DifferentActionButtonIndex = source.DifferentActionButtonIndex;
}
finally
{
EndUpdate();
}
}
}
You can see new properties in your designer:
1. PopupContainerEdit descendant
Now you can use this properties in your custom Edit class.
public class CustomEdit1 : PopupContainerEdit
{
#region Some default stuff for custom edit (constructors, registration, etc).
static CustomEdit1() { RepositoryItemCustomEdit1.RegisterCustomEdit1(); }
public CustomEdit1() { }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public new RepositoryItemCustomEdit1 Properties { get { return base.Properties as RepositoryItemCustomEdit1; } }
public override string EditorTypeName { get { return RepositoryItemCustomEdit1.CustomEditName; } }
#endregion
protected override bool IsActionButton(EditorButtonObjectInfoArgs buttonInfo)
{
int buttonIndex = Properties.Buttons.IndexOf(buttonInfo.Button);
if (buttonIndex == Properties.DefaultActionButtonIndex ||
buttonIndex == Properties.DifferentActionButtonIndex)
{
//Set the Properties.ActionButtonIndex value according to which button is pressed:
Properties.ActionButtonIndex = buttonIndex;
//Set the Properties.PopupControl according to which button is pressed:
if (buttonIndex == Properties.DefaultActionButtonIndex)
Properties.PopupControl = Properties.DefaultPopupControl;
else
Properties.PopupControl = Properties.DifferentPopupControl;
return true;
}
return false;
}
}
2. PopupContainerEditViewInfo descendant
For v13.2 you need to use custom ViewInfo class for your editor:
public class CustomEdit1ViewInfo : PopupContainerEditViewInfo
{
public CustomEdit1ViewInfo(RepositoryItem item) : base(item) { }
public new RepositoryItemPopupBase Item { get { return base.Item as RepositoryItemCustomEdit1; } }
//Show the pressed state when button is pressed or when popup is open.
protected override bool IsButtonPressed(EditorButtonObjectInfoArgs info)
{
var hitObject = PressedInfo.HitObject as EditorButtonObjectInfoArgs;
return
(hitObject != null && hitObject.Button == info.Button) ||
(IsPopupOpen && Item.ActionButtonIndex == info.Button.Index);
}
}
Result
In the result you will get something like this:
and

how to get textbox value from one user control to other in c#

I have two user control's . In the first user control(Class) i have one textbox.
Now in my second user control (Test), i want to get the value of that textbox.
in my page, when user enter a value in texbox of the first usercontrol, how can i get this in the hidden field of the second usercontrol
How can I do this??
I have these properties in my usercontrols
Class User Control
public string Class_ClientId
{
get { return txtClass.ClientID; }
}
public string Class_Text
{
get { return Class; }
set
{
if (value != Class)
{
Class = value;
txtClass.Text = Class;
}
}
}
Test user control
public string KMAT_Text
{
get { return KMATName; }
set
{
if (value != KMATName)
{
KMATName = value;
txtKmat.Text = KMATName;
}
}
}
public string Class
{
get { return _hdnClass; }
set
{
if (value!= _hdnClass)
{
_hdnClass = value;
hdnClass.Value = _hdnClass;
}
}
}
There are a variety of ways to do this. The easiest to implement would be to define a change event on the first user control:
public event EventHandler SomethingChanged;
protected void OnSomethingChanged(EventArgs e)
{
if (SomethingChanged != null)
SomethingChanged(this, e);
}
public string Class_Text
{
get { return Class; }
set
{
if (value != Class)
{
Class = value;
txtClass.Text = Class;
this.OnSomethingChanged(EventArgs.Empty);
}
}
}
Have the page listen for it, and have the page pass the value to the second user control.

Can I hide Value in NumericUpDown control?

Lets say we have 0 displayed in value field of the control and I want that if the value is 0 - display string.Empty (I know that the type of value is decimal and there can be no string inserted instead of decimals in it, but still... Maybe there is some formatting possible there?).
Note: This is dependent on the current implementation of NumericUpDown.
What you need to do is create a new control that inherits from NumericUpDown such that:
public partial class SpecialNumericUpDown : NumericUpDown
{
public SpecialNumericUpDown()
{
InitializeComponent();
}
protected override void UpdateEditText()
{
if (this.Value != 0)
{
base.UpdateEditText();
}
else
{
base.Controls[1].Text = "";
}
}
}
public partial class MyNumericUpDown : NumericUpDown
{
public override string Text
{
get
{
if (base.Text.Length == 0)
{
return "0";
}
else
{
return base.Text;
}
}
set
{
if (value.Equals("0"))
{
base.Text = "";
}
else
{
base.Text = value;
}
}
}
}
It seems that there is only very limited support for changing the formatting.
I have not tried this myself. But you could create a subclass and override the UpdateEditText method to support your custom format. Something like this:
protected override void UpdateEditText()
{
this.Text = Value.ToString(); // Insert your formatting here
}
An easier solution is calling the ResetText() method. You can restore the text changing the Value property.
Example code to hide text when NumericUpDown control is disabled, and restore it on enabled
private void NumericUpDown_EnabledChanged(object sender, EventArgs e)
{
if (numericUpDown.Enabled)
{
if (numericUpDown.Tag != null)
{
// Restore last value
numericUpDown.Value = (decimal)numericUpDown.Tag;
}
}
else
{
// Save last value
numericUpDown.Tag = numericUpDown.Value;
// Just to force value change
numericUpDown.Value = (numericUpDown.Value > numericUpDown.Minimum ? numericUpDown.Minimum : numericUpDown.Maximum);
// Clear text
numericUpDown.ResetText();
}
}
If you only want to hide the value from the user, you can make ForeColor the same as BackColor so the value inside NumericUpDown will be invisible to the user.

Categories

Resources