C# PictureBox rotate vertical - c#

i have create a picture box that shows an image while values changes.I want to show from bottom to top.
The only way that i found is from left to right and from top to bottom
this is the code that i use now from Top to Bottom
//suspbar1.Image.RotateFlip(RotateFlipType.);
suspbar1.Height = 0;
suspbar1.Height = suspbar1.Height + 1;
suspbar1.Height = Convert.ToInt32(SuspensionTravel0 * 1000 / 1.55);
*suspbar1 is my picturebox.

Related

c# panel set auto scroll position causes flickering

We are implementing a picture viewer with zoom in based on center of the image with scroll options.
We have used Forms.Panel with a picture box control for displaying the image and auto scroll set to true.
In order to implement zoom we are using inflate function but this will redraw the image to top left:
To bring it to center we are setting the scroll position to center using the following code:
Rectangle rc = this.Panel_PicBox.ClientRectangle;
Point ScrollPosition = this.Panel_PicBox.AutoScrollPosition;
int height = (int)(PictureBox_png.Height);
int width = (int)(PictureBox_png.Width);
if (rc.Width < width)
ScrollPosition.X = (width - rc.Width) >> 1;
if (rc.Height < height)
ScrollPosition.Y = (height - rc.Height) >> 1;
Point p = new Point(ScrollPosition.X,ScrollPosition.Y);
this.Panel_PicBox.AutoScrollPosition = p;
The code works perfectly for bringing the image to center, only problem is we see a lot of flickering when the scroll position is set.
We have tried double buffer method to reduce flickering but didnt work. Please suggest if there is any other method to reduce flickering.

How can i calculate the distance from the top of pictureBox1 and almost the top of form1?

I have a label with text inside i can change the label size or the label font size each time and check many times but maybe there is a way to calculate it:
label18.Text = "מכם מזג האוויר איננו פעיל כרגע";
This is how i see the text now:
The text in red is in hebrew this is the text i want to change it's size and also to put it in the middle according to the picturebox1 top not on the left like it is now.
And i did a black circle just to show what i mean by " the distance from the top of pictureBox1 and almost the top of form1 ".
I mean this gray area from the above the pictureBox1 and the form1 white area on the top only this gray area i want to make the text in this height and in the middle.
How can i calculate this two values ?
I tried this but it's not in the exact middle:
SizeF size = label18.CreateGraphics().MeasureString(label18.Text, label18.Font);
label18.Left = (pictureBox1.Width / 2) - (((int)size.Width) / 2) + pictureBox1.Left;
label18.Top = pictureBox1.Top - 20;
You don't need graphics or to measure anything. Just set in designer text align = middlecenter and autosize = true
label18.Location = new Point(pictureBox1.Location.X + (pictureBox1.Width / 2 - label18.Width / 2,
pictureBox1.Location.Y - label18.Height);
To center a label you need it get it actual size, then to center it using another control use some simple math to get the coordinate for the control (see below Example 1). I don't know what control the grey bar is but you could center in that by using the size.Width property and doing the same type of calculation.
If you want to fill the grey bar I have added Example 2.
Example 1:
private void CenterLabel()
{
//get the size of the text (you could do this before hand if needed)
SizeF size = label18.CreateGraphics().MeasureString(label18.Text, label18.Font);
//center over picture box control and slightly above
label18.Left = (pictureBox1.Width / 2) - (((int)size.Width) / 2) + pictureBox1.Left;
label18.Top = pictureBox1.Top - 20;
}
Example 2
private void CenterLabel()
{
int fontHeightPixels = (int)(greyBar.Height * .85);
Font font = new System.Drawing.Font("Arial", fontHeightPixels, FontStyle.Regular, GraphicsUnit.Pixel);
string text = "I am centered";
//get the size of the text (you could do this before hand if needed)
SizeF size = label18.CreateGraphics().MeasureString(text, font);
label18.Font = font;
label18.Text = text;
//center over picture box control and slightly above
label18.Left = (pictureBox1.Width / 2) - (((int)size.Width) / 2) + pictureBox1.Left;
label18.Top = (greyBar.Height / 2) - (((int)size.Height) / 2) + greyBar.Top;
}
This is relatively simple with Windows forms:
Dock your label to the top of the form by setting the appropriate property in the Forms designer. The property you want to set is Dock and it should be set to Top.
Change the label's AutoSize property to false.
Change the label's height as desired.
Change the label's TextAlign property to MiddleCentre.
That should do it.
There's more then one way to achieve this goal.
I would suggest the following:
First calculate the width of the picturebox (picturebox.Width)
Find the coordinates on the form where the picturebox resides (picturebox.Location) property of the picturebox)
Then you change the location of your label control --> to Label.Location.X = (picturebox.Width /2) and Label.Location.Y = picturebox.Location.Y ==> now you have the label correctly placed .
Next Set the Height of the Label Control to the Top(distance between the edge of the form and picturebox) value of the Picturebox.
No visual studion from where i am typing so cannot do full code example.
You're done.

Make the bottom corner of the GUI Box stay on place

I am sorry if the title is ugly.
The thing is: I already make the GUI Box in the Unity like this:
If you see on the Image 2, there is an empty space on there, and I don't want to be like that. What I want is the bottom corner is stay on place like the Image 1, only the top corner of it is growing, but the bottom stays on place.
Here is an example image (taken from Heroes of Newerth):
If you see on the Image 1, the bottom corner of the Box that have texts on it, are stays on the bottom corner of the screen, and if you look at the Image 2 and compare it with Image 1, only the top corner of the Box that are growing to the top (minus with the screen resolution) and the bottom corner stays on the bottom corner of the screen resolution.
Is there any way that I can do this?
Here is the code that I am using:
string textOnBox = "This is an example on how does the text on the box is align.\nMy Name is ....\nI am new at Unity and want to learn more about Unity to create and publish my own game using this engine.";
GUIStyle style;
GUIContent boxText;
void OnGUI()
{
boxText = new GUIContent("" + textOnBox);
GUI.color = new Color(0, 0, 0, 0.9f);
style = new GUIStyle(GUI.skin.box);
style.alignment = TextAnchor.MiddleLeft;
Rect boxGUI = GUILayoutUtility.GetRect(boxText, "Box");
boxGUI.x = Screen.width / 2 + 50;
boxGUI.y = Screen.height / 2 + 200;
GUI.Box(boxGUI, boxText, style);
}
Your answer much appreciated!
Thank you very much!
the fontsize from your style could be used to determine the size of the box for 3 lines of text for the height you could do
style.fontSize * 3;

Center UISegmentedControl within a UISearchBar

I am using the built-in search scope with a UISearchDisplayController, and I only have 2 segments.
The problem is that our design needs the buttons to be smaller and centered (it especially looks bad on iPad because the buttons are stretched really wide).
Is there a way to center the UISegmentedControl and make it smaller? I already have the UISegmentedControl pulled out by looping over subViews. And I can set the width of each segment with setWidth:forSegmentAtIndex, but the control is docked to the left. How can I center it?
PS - my app is MonoTouch (Xamarin.iOS), but Obj-C answers are welcome.
Are you adding this via IB or programmatically? In IB, I had to turn off "Autoresize Subviews" and do the resizing of the control dynamically via code. I put the controls I needed to resize into a view that I could bind to then center my control within that view. Here's a sample. I had 2 buttons that I put side-by-side in landscape mode, but it should give you an idea.
// get the current sizes of the things we are moving
CGRect saveRect = self.viewButtons.frame; // the enclosing view
CGRect addLocRect = self.buttonAddLocation.frame; // button 1
CGRect connectRect = self.buttonConnect.frame; // button 2
// This will be set below in one of the if-else branches
CGFloat buttonWidth = 0;
// determine the offset from the left/right based on device and orientation
int offsetLeft = 0;
int offsetRight = 0;
if ([self isIphone]) {
offsetLeft = (UIDeviceOrientationIsPortrait(toInterfaceOrientation)) ? OFFSET_LEFT_PORTRAIT_IPHONE : OFFSET_LEFT_LANDSCAPE_IPHONE;
offsetRight = (UIDeviceOrientationIsPortrait(toInterfaceOrientation)) ? OFFSET_RIGHT_PORTRAIT_IPHONE : OFFSET_RIGHT_LANDSCAPE_IPHONE;
} else {
offsetLeft = (UIDeviceOrientationIsPortrait(toInterfaceOrientation)) ? OFFSET_LEFT_PORTRAIT_IPAD : OFFSET_LEFT_LANDSCAPE_IPAD;
offsetRight = offsetLeft;
}
// change the size & location of the buttons to maximize the area for the location list
// no matter what orientation, the button frame will fill the bottom of the screen
saveRect.size.width = _windowWidth -offsetLeft - offsetRight;
// for Landscape, move the buttons to side-by-side at the bottom of the window
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
// size & move the buttons to fit side-by-side
buttonWidth = (saveRect.size.width)*.4;
// addLocRect.origin.x += offset;
addLocRect.origin.y = saveRect.size.height - addLocRect.size.height ;
connectRect.origin.x = saveRect.size.width - buttonWidth - offsetRight;
connectRect.origin.y = saveRect.size.height - connectRect.size.height;
} else { // Portrait
// move the buttons down to the bottom of the frame, stacked
// size the buttons to be fully across the screen
buttonWidth = saveRect.size.width-2*offsetLeft;
addLocRect.origin.y = 0 ; // at the top of the button view
addLocRect.origin.x = offsetLeft;
connectRect.origin.y = saveRect.size.height - connectRect.size.height;
connectRect.origin.x = offsetLeft;
}
connectRect.size.width = buttonWidth;
addLocRect.size.width = buttonWidth;
self.buttonAddLocation.frame = addLocRect;
self.buttonConnect.frame = connectRect;

How can I move a PictureBox from one panel to another?

I have a Picture Box in a panel and I need to see it move from this panel to another one upon user click. To give you a better picture, I have a connect four game where I have a chip or whatever you call it moving with the mouse on top of the connect four grid and I need it to go in the grid and obviously stay in its place. This is the code I have right now. The chip seems to go down but never stay there
Graphics g = grid.CreateGraphics();
grid.Controls.Add(picBox);
for (int i = 0; i < newYloc; i++)
{
picBox.Location = new Point(newXloc, picBox.Top + 1);
// moves the chip by 1 down each iteration
picBox.Show();
}
if (playerNo == 1) g.DrawImage(red, newXloc, newYloc, 65, 65);
else g.DrawImage(gold, newXloc, newYloc, 65, 65);
where grid is the panel where I have the connect four grid, picBox is the Picture Box which before this piece of code resides in another panel.

Categories