473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Accessing a form control in a differnt class

4
I am currently trying to learn C# just a heads up =)

My probelm, I have a form with many controls. I would like to be able to add and remove controls when needed from the form from another class.

Could someone please explain to me how to do this. I have looked around and found that you can create an instance of your form in the other class but when i try to do that i get a error.

Thanks
Jan 21 '08 #1
7 1033
kenobewan
4,871 Expert 4TB
Simply create your add the controls to your project and reference them in the form. See stickies or search site for more info on using controls. HTH.
Jan 21 '08 #2
I am currently trying to learn C# just a heads up =)

My probelm, I have a form with many controls. I would like to be able to add and remove controls when needed from the form from another class.

Could someone please explain to me how to do this. I have looked around and found that you can create an instance of your form in the other class but when i try to do that i get a error.

Thanks
Are your another add and remove methods running from a thread other than the UI thread?
Jan 22 '08 #3
Eibach
4
Are your another add and remove methods running from a thread other than the UI thread?

I am not following...
Jan 22 '08 #4
Shashi Sadasivan
1,435 Expert 1GB
Set the Modifiers Property of the controls as public.

Click on the control -> view the properties -> select Modifiers -> set value to Public
Jan 22 '08 #5
Eibach
4
Set the Modifiers Property of the controls as public.

Click on the control -> view the properties -> select Modifiers -> set value to Public

I have tried that but still when i try to type... lets say my control, panel, is named myControl

Class Item
{
myControl.Controls.add(anotherControl);
}

it doesnt seem to work
Jan 22 '08 #6
Shashi Sadasivan
1,435 Expert 1GB
what is myControl and another control?
which one is from the other form?
you need to specify those refrences.
Jan 23 '08 #7
Eibach
4
what is myControl and another control?
which one is from the other form?
you need to specify those refrences.
sorry

Thank you for the reply although that does not answer my question. Let me discribe my problem better. I am creating a game. I have a couple classes for differnt things one is called Item.cs that inharets a PictureBox and i have a Player.cs. I want to be able to add items to the screen when a player enters a certain room, and when the player double clicks on the PictureBox, Item, i want it to dissapear and appear in the players inventory. Now i found out a way to add the controls, but only when the form is first loaded here is my method.


public void AddControls()
{
foreach (Weapon weapon in Program.player.GetCurrentRoom().Weapons)
{
pnlLevel.Controls.Add(weapon);
}

}

I have one more question aswell. I want to have the PictureBox, player, move smoothly across the screen mind you this is a 2D game. so this is what i have to move the player.

private void Amarix_KeyDown(object sender, KeyEventArgs e)
{
//One key is pressed
if (e.KeyCode == Keys.W || e.KeyCode == Keys.Up)
{
pbxPlayer.Top -= 8;
}
if (e.KeyCode == Keys.S || e.KeyCode == Keys.Down)
{
pbxPlayer.Top += 8;
}
if (e.KeyCode == Keys.A || e.KeyCode == Keys.Left)
{
pbxPlayer.Left -= 8;
}
if (e.KeyCode == Keys.D || e.KeyCode == Keys.Right)
{
pbxPlayer.Left += 8;
}
}

So i was wondering how to make it so if you pressed like the up key and the right key at the same time the player would go in a diagnal?

thank you again for your help!
Jan 23 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tom Meuzelaar | last post by:
Hello: I'm using VB6 in VS enterprise. I'd like to place an HTML form inside a VB container, have a user fill out the form information, click a submit button, and then have the program capture...
2
by: Greg Merideth | last post by:
Using Visual C# I created two forms such as namespace test { public class SystemTray : System.Windows.Forms.Form { public createwindow() { stuff here; } public fadewindow() { stuff to fade...
3
by: Vivek Sharma | last post by:
Hi, I have created a dropdownlist as a web user control. I am using its multiple instances on the webpage. How do I access the selectedValue of each instance? All the instances have different...
1
by: tmaster | last post by:
Within a class, can I create a property that is a listview? Here's what I tried, but it doesn't seem to work: '------------ create property to give the second form access to the first form's...
9
by: Blake Weaver | last post by:
Ok, this is probably a no-brainer for most of you but its escaping me and I can't even seem to find the answer in any documentation. How do you access a friend variable of one class, from another...
6
by: Jon Masterson | last post by:
Hi All I am trying to access a control on my main form from a class. The control is a Windows Media Player which I do not think I can instantiate in code. The class needs to pass the file name...
6
by: evandelagrammaticas | last post by:
Hi all. I have spent the better part of a day scouring the newsgroups and I am sure that I must have come across the solution a number of times - but I am still a real newbie at asp.net so please...
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
0
by: rahulsubramanyam | last post by:
Hi All, I have an application written in c#. A Windows form in it has many controls which goes beyod the viewable area of the form. So I have enabled auto scroll property of the form. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.