Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello i was looking on web for this but no luck
I have two Forms (Form1,Form2)
Form1 Will contain Listbox1 and Item (like Burger) Buttons
Form2 will contain textboxes to set a properties and values of Form1 buttons
Example
TextBox1.text should set Button Text (name of the burger)
TextBox2 should set button value (Price of the burger)
TextBox3 should set a Button Image

and i need to create a new button from Form2 on Form1 of course i will need that whenever i open the Form2 and need to create new button

What I have tried:

I imagine i will need data tables for this because i will need to update maybe once the price or image
For updates i can have ComboBox in Form2 with the list of Items (Buttons)
So basically I know how to Insert in database but how to set that to the Button and of course how to create new button from Form2

Can you help me with this
Thank You
Posted
Updated 27-Jul-17 1:37am

Don't. When you start accessing controls on a different form, you lock the two together and you can no longer modify one without considering the effects on the other - controls are private for a reason, and that reason is to prevent this kind of thing which is decidedly against the principles of OOPs.

Instead, Form2 creates an event (or several events) which it raises when it wants to change Form1, and Form1 handles the events, using Properties on Form2 to access teh revised information.
Perhaps "BurgerSelected", "PriceChanged" or similar would be good?

This sounds complex, but it isn't, not really - and it makes your code a lot more readable and maintainable.
Have a look at this: Transferring information between two forms, Part 2: Child to Parent[^] - it includes an example.
 
Share this answer
 
Comments
Member 13084733 27-Jul-17 23:20pm    
ok i can't use parent controll because this two form will be on different PC basically i will need just a code and data base. data base for the prices and images and on Form 2 textBoxes to change or add that values
OriginalGriff 28-Jul-17 4:10am    
That is a whole different problem, and you are going to have to address that very carefully.
It's not a problem we can solve for you in a little tiny text box: you need to think very carefully about how many applications are involved, how much bandwidth you can afford, update frequency, physical connections, database type and capacity, ... a whole load of things. It's not as simple as it would be within the same app at all, it is orders of magnitude more complex.
Member 13084733 3-Aug-17 4:06am    
I have figure it out how will i create this i will use data base with schedule to update and update button if needed
but now i have different problem
do you have any idea how to load text image and a value to 50 buttons from data table
i know for query select but in form load i need to create query who will have next :
select id 1,image value and name from table
to show it on button1
and etc for button 2
AND if i have value for button 25 if not to hide it
Buttons are just like any other control. They are listed in their parent's Controls collection. Their properties can be set at runtime. That's what the designer generates code for. Have a look at your Form1.designer.cs file. There you see how it's done. But don't change code there because any later change in designer will overwrite your change in code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900