- Joined
- Feb 5, 2008
- Messages
- 6,252
- Points
- 83
Hey guys,
I'm trying to code up something basic in Visual C# as a learning project, hoping to step up my coding game and eventually be of some use to those fine folks over at ME3 Explorer project. But anyway,
What I'm trying to accomplish is sort of a Window 7 style taskbar.
There is a toolset, still work in progress, made for modifying various files of an Unreal Engine 3 game, Mass Effect 3.
Interface of the toolset (Form1) offers a variety of tools, and I'd like to add a small taskbar-like panel to the bottom so you can easily keep track of what tools do you currently have open.
Two parts of my goal are:
When an icon in taskbar is clicked, the corresponding took is brought up to the top and focus switched to it. That I already have completed.
Second part is, when the tool (form) is closed, the corresponding icon from the taskbar should be removed. That is what I'm having problems with.
I have created a new Panel to act as a taskbar. It will create Controls, specifically Image Boxes, as tools are ran.
Controls have an event handler when click is made.
My class "taskbar" which contains the most of my code (as not to disturb the original code as much as possible), defines these public variables:
A public function is made which when used, will add a control to the panel:
In class taskbar:
This function is called within Form1 like this:
In Form 1:
Later when a click event is being made:
In class taskbar:
Now here's where I'm stuck.
I'm trying to create new function in class taskbar:
I know for a certain I will have this in :
Firstly I'd like to know how would I go on about to manipulate Form1's Panel controls from my Class taskbar.
This obviously will not work:
public static void RemoveTool()
{
Form1.panel1.Controls.Remove( ... control ...);
x_pos -= 50;
}
As I cannot reference a panel in Form1, giving me error:
How would I go about referencing it?
Second, how would I match the corresponding Control in the panel, with the Form that just closed?
For example, in previous example of PCCExplorer tool, let's create a new event handler for FormClose event:
How would I use this to match it to the icon it created when it got called from Form1?
Sorry for the long-ish thread, and I'd really appreciate any help. I'm really trying hard to learn some coding because it definitely looks like a very useful skill to have, and that's not taking into account later college subjects requiring this.
Thanks in advance!
I'm trying to code up something basic in Visual C# as a learning project, hoping to step up my coding game and eventually be of some use to those fine folks over at ME3 Explorer project. But anyway,
What I'm trying to accomplish is sort of a Window 7 style taskbar.
There is a toolset, still work in progress, made for modifying various files of an Unreal Engine 3 game, Mass Effect 3.
Interface of the toolset (Form1) offers a variety of tools, and I'd like to add a small taskbar-like panel to the bottom so you can easily keep track of what tools do you currently have open.
Two parts of my goal are:
When an icon in taskbar is clicked, the corresponding took is brought up to the top and focus switched to it. That I already have completed.
Second part is, when the tool (form) is closed, the corresponding icon from the taskbar should be removed. That is what I'm having problems with.
I have created a new Panel to act as a taskbar. It will create Controls, specifically Image Boxes, as tools are ran.
Controls have an event handler when click is made.
My class "taskbar" which contains the most of my code (as not to disturb the original code as much as possible), defines these public variables:
Code:
public static Image symbol;
private static PictureBox tool_icon;
public static List<Form> tools = new List<Form>();
A public function is made which when used, will add a control to the panel:
In class taskbar:
Code:
public static Control AddTool(Form tool, Image symbol)
{
tool_icon = new PictureBox(); //new control initialized
tool_icon.Location = new Point(x_pos, 2);
x_pos += 50; //set position to stack against the previously made control
tool_icon.Size = new Size(50, 60);
tool_icon.Click += new EventHandler(tipek_onclick); //event handler for when control is clicked
tool_icon.Image = symbol; //tool specific image
tool_icon.Tag = tools.Count().ToString(); //specifying tag which will later be used in click event
tools.Add(tool); //adding an originating Form to the list
return tool_icon; //finally, returning the Control to originating form
}
This function is called within Form1 like this:
In Form 1:
Code:
PCCExplorer px = new PCCExplorer();
lang.SetLang(px); //ignore this
px.MdiParent = this; //ignore this
px.WindowState = FormWindowState.Maximized; //ignore this
panel1.Controls.Add(taskbar.AddTool(px, imageList1.Images[0])); //creating a new control in current Form1 with AddTool function, forwarding the PCCExplorer form tool and it's icon to the function
...
Later when a click event is being made:
In class taskbar:
Code:
public static void tipek_onclick(object sender, EventArgs e)
{
Control m = sender as Control; //sender of argument is control, ImageBox from form1
Form active = tools[Convert.ToInt32(m.Tag)]; //gets a corresponding Form from the list of forms, by the Tag count
active.Focus();
}
Now here's where I'm stuck.
I'm trying to create new function in class taskbar:
Code:
public static void RemoveTool()
{
}
I know for a certain I will have this in :
Code:
public static void RemoveTool()
{
x_pos -= 50;
}
Firstly I'd like to know how would I go on about to manipulate Form1's Panel controls from my Class taskbar.
This obviously will not work:
public static void RemoveTool()
{
Form1.panel1.Controls.Remove( ... control ...);
x_pos -= 50;
}
As I cannot reference a panel in Form1, giving me error:
Error 4 An object reference is required for the non-static field, method, or property 'ME3Explorer.Form1.panel1'
How would I go about referencing it?
Second, how would I match the corresponding Control in the panel, with the Form that just closed?
For example, in previous example of PCCExplorer tool, let's create a new event handler for FormClose event:
Code:
private void PCCExplorer_FormClosed(object sender, FormClosedEventArgs e)
{
}
How would I use this to match it to the icon it created when it got called from Form1?
Sorry for the long-ish thread, and I'd really appreciate any help. I'm really trying hard to learn some coding because it definitely looks like a very useful skill to have, and that's not taking into account later college subjects requiring this.
Thanks in advance!