I want to access labelNummer.Text from my User Control in my form.
Form
if (idPartijen.Contains(labelNummer.Text))
{
con.SqlQuery("SELECT * FROM `kandidaat` where `partijnummer` =#nummer ");
con.Cmd.Parameters.Add("#nummer", MySql.Data.MySqlClient.MySqlDbType.VarString).Value = labelNummer.Text;
User Control
public string KandidaatNummer
{
set
{
Nummer = value;
labelNummer.Text = Nummer;
}
}
Your UserControl
public partial class MyUserControl : UserControl
{
public MyUserControl()
{
InitializeComponent();
}
private void MyUserControl_Load(object sender, EventArgs e)
{
}
public string KandidaatNummer
{
get
{
return labelNummer.Text;
}
set
{
labelNummer.Text = value;
}
}
}
Let's say that your user control has a name called: MyUserControl1
if (idPartijen.Contains(myUserControl1.KandidaatNummer)) { ... }
Related
I need to display the picturebox that is formed in the main form in the usercontrol, but also save subscriptions to this picturebox.
In this class, I fill in the fields and then use foreach to pass the picturebox to the usercontrol
public class UserCtr
{
public event Action<List<Users>> ClickPicture;
public event Action<List<Users>, Group> DoubleClickPicture;
public Group group { get; set; }
public PictureBox picture { get; set; }
public List<Users> users { get; set; }
public UserCtr(Group group, PictureBox picture, List<Users> users)
{
this.group = group;
this.picture = picture;
this.users = users;
this.picture.Click += PictureClick;
this.picture.MouseDoubleClick += PictureDoubleClick;
}
private void PictureClick(object s, EventArgs e)
{
ClickPicture(users);
}
private void PictureDoubleClick(object s, EventArgs e)
{
DoubleClickPicture(users, group);
}
}
foreach loop
foreach (var item in groups.users)
{
item.picture.Image = yellow;
panel.Controls.Add(new UserControl1(item.picture)
{
Text = item.user.Name,
//pb = item.picture
});
}
My usercontrol
public partial class UserControl1 : UserControl
{
public UserControl1(PictureBox pic)
{
InitializeComponent();
Load += (s, e) => pictureBox1 = pic;
Invalidate();
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
label1.Text = Text;
}
}
}
The label is filled in, and the picturebox is empty
I want to create a C# Windows Form application where there is a flow layout panel, filled with User Control elements. Every time I click an element, the some labels must show its attributes. However, the click event doesn't register. I added some breakpoints on the show_preview() method and it never calls the method. The Load event is calling show_preview but I want to do change the labels acordinging to a User Control being clicked.
This is the Form:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
load_plots();
}
private void load_plots()
{
ArrayList items = new ArrayList();
for (int i = 0;i<100;i++)
{
PlotItem plot = new PlotItem();
plot.Place = "Ilion";
plot.Price = i * 1000;
plot.Space = i * 10;
plot.Title = "Plot No." + i;
plot.Width = flowLayoutPanel1.Width - 30;
plot.Click += new EventHandler(this.show_preview);
items.Add(plot);
flowLayoutPanel1.Controls.Add(plot);
}
}
private void show_preview(object sender, EventArgs e)
{
PlotItem clicked = sender as PlotItem;
plot_title.Text = "Hello";
plot_size.Text = clicked.Space.ToString();
plot_value.Text = clicked.Price.ToString();
}
This is the Plot Item:
public partial class PlotItem : UserControl
{
public PlotItem()
{
InitializeComponent();
}
#region Properties
[Category("Plot Object")]
private String _place;
public String Place
{
get { return _place; }
set { _place = value; }
}
[Category("Plot Object")]
private double _price;
public double Price
{
get { return _price; }
set { _price = value; label_price.Text = value.ToString() + "€"; }
}
[Category("Plot Object")]
private String _use;
public String Use
{
get { return _use; }
set { _use = value; }
}
[Category("Plot Object")]
private double _space;
public double Space
{
get { return _space; }
set { _space = value; label_size.Text = value.ToString() + "m2"; }
}
[Category("Plot Object")]
private String _title;
public String Title
{
get { return _title; }
set { _title = value; label_title.Text = value; }
}
[Category("Plot Object")]
private Image _icon;
public Image Icon
{
get { return _icon; }
set { _icon = value; plot_preview.Image = value; }
}
#endregion
private void panel1_MouseEnter(object sender, EventArgs e)
{
this.BackColor = Color.Silver;
}
private void panel1_MouseLeave(object sender, EventArgs e)
{
this.BackColor = System.Drawing.SystemColors.Control;
}
Thanks for your time.
I have one question about how to get and set in c #
I enter data in Page1 through Class1 and appears in Page2 but unachievable set values in Page1.
Page1
namespace textMuc
{
public partial class Page1 : PhoneApplicationPage
{
public Page1()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Class1 cl = new Class1();
cl.Muc = 123;
}
}
Page2
namespace textMuc
{
public partial class Page2 : PhoneApplicationPage
{
public Page2()
{
InitializeComponent();
}
Class1 cl = new Class1();
private void Button_Click(object sender, RoutedEventArgs e)
{
txthien.Text = cl.Muc.ToString();
}
}
}
Class1
namespace textMuc
{
public class Class1
{
private int capdo = 100;
public int Muc
{
get { return capdo; }
set { capdo = value; }
}
}
}
What should I do?
Thank!!!
I have found your problem with static
namespace textMuc
{
public class Class1
{
private static int capdo = 100;
public int Muc
{
get { return capdo; }
set { capdo = value; }
}
}
}
Try keeping the capdo variable static...
namespace textMuc
{
public class Class1
{
private static int capdo = 100;
public int Muc
{
get { return capdo; }
set { capdo = value; }
}
}
}
I have some label that should display actual amount of items that contain BindingList that bound to the DataGridView.
I tried to bind in this way:
CountOfLoadedItemsLabel.DataBindings.Add("Text", _items.Count, String.Empty);
But when BindingList updates, the label that bound to its Count property not changes.
Never used BindingList<T> but this worked for me:
public partial class Form1 : Form
{
private BindingList<Test> list;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.list = new BindingList<Test>
{
new Test(1,"Entry"),
new Test(2,"Another Entry")
};
dataGridView1.DataSource = new BindingSource(list,null);
list.ListChanged += list_ListChanged;
list.Add(new Test(3, "After Binding"));
}
void list_ListChanged(object sender, ListChangedEventArgs e)
{
CountOfLoadedItemsLabel.Text = string.Format("Items: {0}", list.Count);
}
}
public class Test
{
public int Id { get; set; }
public string Name { get; set; }
public Test(int id, string name)
{
this.Id = id;
this.Name = name;
}
}
In my wpf application, I've created two view classes, DayView and CustomView. In DayView, there is a listbox consist of some entries. In listbox, there is stackpanel with 5 textboxes. In my CustomView class, also I've created stackpanel with 5 textboxes. when I enter data into those textboxes of CustomView and click on save button,the new entry should create and data should saved in respective textboxes of DayView.
CustomView class:
namespace TimeSheet
{
/// <summary>
/// Interaction logic for CustomView.xaml
/// </summary>
public partial class CustomView : Window
{
public List<Harvest_Project> projectList { get; set; }
public List<Harvest_Client> clientList { get; set; }
public Harvest_Project selectedProjectid { get; set; }
public Harvest_Client selectedClientid { get; set; }
private string client { get { return ClientText.Text; } set { ClientText.Text=value;} }
private string application { get { return ApplicationText.Text; } set { ApplicationText.Text = value; } }
private string starttime { get { return StartTimeText.Text; } set { StartTimeText.Text = value; } }
private string stoptime { get { return StopTimeText.Text; } set { StopTimeText.Text = value; } }
private string task { get { return TaskText.Text; } set { TaskText.Text = value; } }
private string project { get { return ProjectText.Text; } set { ProjectText.Text = value; } }
public CustomView()
{
InitializeComponent();
this.DataContext = this;
Globals._globalController.setCustomViewWindow(this);
clientList = Globals._globalController.harvestManager._CLIENTLIST;
projectList = Globals._globalController.harvestManager._PROJECTLIST;
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
if (sender is Harvest_TimeSheetEntry)
{
//Harvest_TimeSheetEntry entry = new Harvest_TimeSheetEntry();
//if (!entry.isSynced)
//{
// entry.ClientNameBinding = client;
// entry.ApplicationNameBinding = application;
// entry.StartTimeBinding = starttime;
// entry.StopTimeBinding = stoptime;
// entry.TaskNameBinding = task;
// entry.ProjectNameBinding = project;
//}
Globals._globalController.getDayViewWindow.Show();
this.Hide();
}
}
private void ClientComboBoxChanged(object sender, SelectionChangedEventArgs e)
{
string text = (sender as ComboBox).SelectedItem.ToString();
}
private void ProjectComboBoxChanged(object sender, SelectionChangedEventArgs e)
{
string text = (sender as ComboBox).SelectedItem.ToString();
}
}
}
I don't understand, how should i save this data in DayView listbox. Please suggest some ways.!
This is DayView window
[1]: http://i.stack.imgur.com/1Qi0e.png
This is CustomView window!
[2]: http://i.stack.imgur.com/mACxR.png
In my opinion it's more suitable to use an mvvm Framework to make your solution more structured, and then use a Messenger to make communication between your views.