-
q12-
I have a UserControl named Background and a simple class named NavigationArrows.
This NavigationArrows class is loading a bunch of *.png's images displaying some arrows that are lit OR unlit, depending on keypressed by user.
The UC Background, is containing the BIG Background image and is panning it through the Background_KeyPress event.
----
What I want is simple:
I want to connect the arrows to the KeyPress event.
(to show the lit arrow image when a key is pressed)
----
BUT !
I can do it very simple, all inside UC. But I dont want that.
I want the NavigationArrows Class to contain every aspect of the arrows!!!!
loading the images, the !!!Events!!!, position on canvas, size of the arrows, and the rest that I can't think of now. In a word, to contain all the properties, events, methods, that are related to the arrows class/(or object if you want).
My big problem is the connections between the 2 clases. How to connect them in a simple and elegant way, in a LOGICAL way, in a NON-Confusing way.
My way of linking these 2 clases is very confusing in code. Too many arguments here and there. (It is not confusing because of the names I gave - not that) It is confusing because of the structure i must build !!! It is extremely convoluted and wtf at every corner.
----
Right now, in this stage I am presenting the code, it is the begining.
But I will have to load and link the rest of the arrow images (i did not show that here)- it is not scripted yet. But I know from experience, it will become agglomerated very quickly.
Also, I will have to load OTHER classes/objects into canvas too. This Arrow class is just a test. If I have to load 100 clases, each of them containing it's own SET of images (let's say 50 img per class), and with their own Methods and properties, and with their own !!EVENTS!!, that they must be conected to the Background object (somehow).
Do you see what I mean by LOGICAL way and NON-Confusing ?
It must be like a on/off switch this link between object and class. Something like:
UI.NavigationArrows navArrows = new UI.NavigationArrows();
navArrows.Active();
navArrows.pozition(0,0);
navArrows.size(20,20);
And thats it. And they must perform and do their jobs!
How can I achieve this?
Thank you,
-
q12-
What I have tried:
public partial class Background : UserControl
Rectangle navArrowsRectangle = new Rectangle(10, 10, 100, 100);
void Background_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(q1.backgroundImage, q1.rectangle);
string imgName = "UI\\NavigationArrows OFF.png";
Image BaseImg = Image.FromFile(imgName);
e.Graphics.DrawImage(BaseImg, navArrowsRectangle);
}
void Background_KeyPress(object sender, KeyPressEventArgs e)
{
int th12 = 0;
if (e.KeyChar == 'w')
{
if (q1.rectangle.Y < 0) q1.rectangle.Y += q1.amount;
else q1.rectangle.Y = 0;
}
if (e.KeyChar == 's')
{
th12 = -q1.imgy + this.Height;
if (q1.rectangle.Y > th12) q1.rectangle.Y -= q1.amount;
else q1.rectangle.Y = th12;
}
if (e.KeyChar == 'a')
{
if (q1.rectangle.X < 0) q1.rectangle.X += q1.amount;
else q1.rectangle.X = 0;
}
if (e.KeyChar == 'd')
{
th12 = -q1.imgx + this.Width;
if (q1.rectangle.X > th12) q1.rectangle.X -= q1.amount;
else q1.rectangle.X = th12;
}
this.Refresh();
}
and this is my second class that I want it remodeled to become "In Itself".
I mean that it should plug and play into Background class.
public class NavigationArrows
{
public void InitializeNavigationArrows()
{
string imgName = "UI\\NavigationArrows OFF.png";
BaseImg = Image.FromFile(imgName);
}
public Image BaseImg;