Scaling down a high resolution set of co-ordinates? - c#

Here is some background to the problem. We are working with an EyeVis wall setup, see this link: http://www.eyevis.co.uk/
The EyeVis wall can have any number of 'windows' displayed on the wall at any time. We query the wall for its size dimensions, and then query it for a list of all the windows currently being displayed on the wall. This comes back as a set of co-ordinates as follows:
Left, Top, Width, Height
So at this stage we have the size of the wall, and the co-ordinates of each window being displayed within that wall.
What we need to do is display a representation of the wall's layout on a monitor being viewed by the controller. The controller will then select one of the windows (from the monitor) and this window will be enlarged on the EyeVis wall.
I have tried a few things, in the hope that there might be a simple way to achieve this. One idea I had was this:
Create a panel in code with the dimensions of the wall.
Add each window to this panel using the co-ordinates.
Add the main panel to a form and dock the panel
I thought this would auto scale all the panels within the main panel and we would see the layout, but docking at runtime doesn't seem to behave the way I imagined?
This is the code I had: (Using C#)
Panel mainPanel = new Panel();
mainPanel.Width = eyeVisWallWidth;
mainPanel.Height = eyeVisWallHeight;
foreach (Window thisWindow in windowList)
{
Panel newWindow = new Panel();
newWindow.Top = thisWindow.windowTop;
newWindow.Width = thisWindow.windowWidth;
newWindow.Height = thisWindow.windowHeight;
newWindow.Left = thisWindow.windowLeft;
Label newLabel = new Label();
newLabel.Text = thisWindow.windowID.ToString() + ":" + newWindow.Height + ":" + newWindow.Width;
newWindow.Controls.Add(newLabel);
newWindow.BorderStyle = BorderStyle.FixedSingle;
mainPanel.Controls.Add(newWindow);
}
this.panel1.Controls.Add(mainPanel);
mainPanel.Dock = DockStyle.Fill;
mainPanel.Anchor = AnchorStyles.None;
So now I'm starting to think this might have to be solved with math, which is really not my strong point. Does anyone have any advice or a pointer to something which might help me with this?
Any help appreciated!
Regards
Adrian

Forgot to close thise, we just ended up dividing all the co-ordinates by a common factor.

Related

How to determine if control is outside of Form?

I am trying to determine if a dynamically added control is outside of the form.
At first, I thought it might be possible to calculate it by getting the height of the form, and location of the dynamically added control.
But I noticed that the Control.Location and Form.Height have "nothing" in common.
I don't think I really understand what the correlation is between Height and Location.
For example:
I thought that if your form has a height of 500, and I put the control at the bottom of the form, it should give the Location: X, 500 (X is width, not relevant here). But this is not correct, it shows me for example: X, 465. Am I missing something?
So I need to be able to recognize if the control is outside of the form, even if it's just one pixel.
I've found several similar questions here on SO, yet this does not really give me the answer that I need, unfortunately.
So, is there any way to do this? Is it possible to calculate it?
The Height of the form also includes the height of the title bar and borders.
You can use the ClientSize of the form:
From the documentation on MSDN:
The size of the client area of the form is the size of the form excluding the borders and the title bar. The client area of a form is the area within a form where controls can be placed. You can use this property to get the proper dimensions when performing graphics operations or when sizing and positioning controls on the form. To get the size of the entire form, use the Size property or use the individual properties Height and Width.
The position of the control is relative to its container, so (0,0) is the left upper corner inside the form.
I know this is an older thread, but you can try using this method:
public static bool IsOutofBounds(Form form, Control control)
{
int controlEnd_X = control.Location.X + control.ClientSize.Width;
int controlEnd_Y = control.Location.Y + control.ClientSize.Height;
if (form.ClientSize.Width < controlEnd_X || form.ClientSize.Height < controlEnd_Y)
{
return true;
}
else
{
return false;
}
}
It works for checking whether a control is out of bounds of its parent form.
You could use this code to check if controls is inside form:
var Inside = frm.ClientRectange.Intersect(ctrl.Bounds) == ctrl.Bounds;
the top left corner of a form is (0,0) lower right corner is (formHeight, fromWidth).
to check this place two text boxes on a form and write this code in the mouse move event to see how x and y change.
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
textBox1.Text = e.X.ToString();
textBox2.Text = e.Y.ToString();
}
Note that there is an difference between the number returned from the edge of the form and the size chosen by you. In my 500*500 form it is actually 460*483. the difference is always the same for any border style and any resolution.
To place a control on your form use the location structure in the form or use the top and left properties for the control; top = x, left = y.
Remember your offset from the actual height and width you measured and the dimension of the control.
To add a button with the following dimensions 80*30 in the bottom right corner I would right something like this:
button1.Location = new System.Drawing.Point(402, 430);
bottom left corner:
button1.Location = new System.Drawing.Point(0, 430);

Panel animation

I'm trying to perform a slide in/out animation on my windows phone project.
The effect I'm trying to create is that a user presses a button, that a list of buttons ( a panel ) slides in from the side and the current page slides a bit off screen.
Look at a good example here ( the panel is fully slided in, so a small part of the active page is still visible )
Now I think the animations are not that difficult ( but any tips on how to create it are welcome ), but I was wondering how do you add the subtle shadow effect?
If you look at the image you will notice that it's like the panel is underneath the active screen, because of the shadow...
I might have an idea.
-Create a timer, for each tick you execute this:
int x = pnl.Location.X;
int y = pnl.Location.Y;
pnl.Location = new Point(x + 1, y);
-Then you should create an if to stop the timer when the panel is on the right position, for example:
if (x == 20)
{
tmrMove.Stop();
}

What's the best way to design a full screen application in C#?

I want to know the best way to design a full screen form, like positioning controls in a way that they won't get messed up if the user's resolution is different.
This is my fullscreen code:
int w = Screen.PrimaryScreen.Bounds.Width;
int h = Screen.PrimaryScreen.Bounds.Height;
this.Location = new Point(0, 0);
this.Size = new Size(w, h);
Anchors and Docks.
The Anchor will bind the control. The Dock property sets how it expands/shrinks.
So if you assign a button anchor to "Top, left" it's size and position stay locked on those sides. So if you dragged the Form window wider, the object would expand to towards the right and towards the bottom.

How can I make a background panel from a form transpart/invisible in an XNA window?

I have an XNA project that utilizes the Windows.Forms to create the GUI. Our GUI consists of a left panel and right panel. They both have a image laid over them(let's call them the panel images). Those images have buttons with images over them. Now the panel images don't completely cover the panel. Now what we want to do is make the panel invisible or transparent so you only see the panel images. In the picture below I circled what I want to be transparent/invisible. As you can see on the upper part of the project it already looks transparent but that is only because it blends in with the background on the XNA scene. On the bottom where the panel is over the ground you can see how the panel extends further than the panel images. So, does anyone know how I can make those parts invisible/transparent.
Alright, we've messed around with making the panel color Color.Transparent, magenta(XNA transparent color) and those attempts haven't worked. Any input/advice is welcome and much appreciated.
Here is the code that sets up the panel:
this.pnlLeftSide.BackgroundImage = global::Referenceator_UI.Resources.LeftBar;
this.pnlLeftSide.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.pnlLeftSide.Controls.Add(this.btnScreenShot);
this.pnlLeftSide.Controls.Add(this.btnScale);
this.pnlLeftSide.Controls.Add(this.btnMove);
this.pnlLeftSide.Controls.Add(this.btnRotate);
this.pnlLeftSide.Controls.Add(this.btnSelect);
this.pnlLeftSide.Location = new System.Drawing.Point(0, 0);
this.pnlLeftSide.Name = "pnlLeftSide";
this.pnlLeftSide.Size = new System.Drawing.Size(197, Screen.PrimaryScreen.WorkingArea.Height);
this.pnlLeftSide.Dock = DockStyle.Left;
this.pnlLeftSide.BackColor = controlColor; //this what we want invisible/transparent
-Thank you stackoverflow community
Try setting Region property of your panels. You can create necessary Region objects manually (by enumerating lines describing visible polygon) or use some method which converts image with transparency color key to Region (easily googled - https://stackoverflow.com/questions/886968/how-do-i-convert-an-images-transparency-into-a-region for example).
Since geometry of your panels does not seem to be too complex, you can create Region manually following way:
using(var gp = new System.Drawing.Drawing2D.GraphicsPath())
{
// Here goes series of AddLine() calls.
// You must
// gp.AddLine(0, 0, leftPanel.Width, 0);
// ...
gp.CloseFigure();
return new Region(gp);
}
Note that you'll get sharp edges with this method (even if it works). Consider rendering all that GUI using XNA.

Resizing a grid control programatically over a period of time

G'day,
I am attempting to simulate the old XBox 360 GUI with the sliding tabs (Remember, you'd press left or right and the content would slide in depending on the tab?) Anyways, at the moment, I have this working well, however I cannot get the "animation" working.
When the user presses left arrow or right arrow, my OpenWindow(int iIndex) method will be called, where iIndex is the index to the next or previous "window" to be slid in. (Not a window... each "Window" is a struct with a parent grid control containing a button and a smaller grid control that contains the windows contents.)
Now, my problem lies with resizing the parent grid control. When it is slid in, it is resized by calling mygrid.Width += 1; That works, but I don't see it happen over a determined period of time, it just lags a bit and then resizes to the required width. Whereas if I call this.Width += 1 in the same method, (this being the main program window) the window resizes how I want the grid control to resize. I've tried UpdateLayout() but to no avail. This tells me my timing is okay.
If anyone could be of assistance, it would be greatly appreciated.
Here is my OpenWindow method...
public void OpenWindow(int iIndex)
{
int iInterval = 1;
for (int i = (int)myDict[iIndex].Shell.Width; i < (int)stack_outter.Width; i += iInterval)
{
myDict[iIndex].Shell.Width += 1;
myDict[iIndex].Shell.UpdateLayout();
System.Threading.Thread.Sleep(1);
}
myDict[iIndex].Shell.Width = stack_outter.Width - (BUTTON_WIDTH * (myDict.Count - 1));
}
myDict is a Dictionary, Shell is the grid that I am attempting to animate when resizing. Sorry about the code, it's messy, my code is always hacked when I am trying to get stuff working :)
Thanks,
Ash
Neried Web Solutions
Your OpenWindow method is happening on the Dispatcher thread. That's also the thread responsible for rendering, so as long as your OpenWindow method doesn't return, nothing gets rendered.
The proper way to fix this would be to animate the Width property. I don't have any experience in starting animations from code (I've only used them in the past for things like a fade-in button highlight on mouse over, which is more easily done from WPF), but I took a quick read-through this page, Animation Overview on MSDN, and I think you'll want something like this:
DoubleAnimation myDoubleAnimation = new DoubleAnimation();
myDoubleAnimation.From = myDict[iIndex].Shell.Width;
myDoubleAnimation.To = stack_outter.Width;
myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.5));
myDoubleAnimation.AutoReverse = false;
myDoubleAnimation.RepeatBehavior = new RepeatBehavior(1.0);
myStoryboard = new Storyboard();
myStoryboard.Children.Add(myDoubleAnimation);
Storyboard.SetTarget(myDoubleAnimation, myDict[iIndex].Shell);
Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(FrameworkElement.WidthProperty));
myStoryboard.Begin(myDict[iIndex].Shell);

Categories

Resources