I'm a bit stuck with this one.
I'm writing a visual Semaphore flag signalling application, and I'm having a bit of trouble with the positioning of labels for left and right arms.
This is the code before:
private void leftHandDown()
{
display.DrawLine(penLeftArm, centXCoord, centYCoord, LHDownXCoord, LHDownYCoord);
lblLeftHand.Top = LHDownYCoord;
lblLeftHand.Left = LHDownXCoord;
lblLeftHand.Show();
}
And this is what it looks like:
http://i137.photobucket.com/albums/q221/omar319/sema.png (I don't have any rep to post photos on here). I have set the background to blue, as I'm also trying to pin down another problem (labels leave a white box when they change position, not sure why).
I would like the labels to appear at the end of the hands drawn by the pen (end coordinates LHDownXCoord and LHDownYCoord) but the labels are always offset by -80px on the y-axis. The Right Hand label I have added 75px to the Y axis coordinate.
Any idea what is causing the offset?
Cheers,
Omar
I think the labels need to be offset by the top left coordinates of your display control
Related
Is it possible to draw a line at the border of the screen, like an "inline" with a consistent width of lets say 10 pixels, so that it aligns to the edges of the screen, even at the rounded corners?
Like this:
normal screen
with the wanted inline (Orange line)
Is there a unity solution? (Otherwise any other solution would be great too! Android studio maybe?)
What I want to achieve is a line that's always the same shape as the screen borders, on every screen, no matter the radius of the corners
I don't think this is possible in normal ways, since Unity considers the screen as a rectangle, so it will give you no information about the shape of the corners of your screen.
However, it is not impossible. You can use SystemInfo.deviceModel to get the model of a device and then you can retrieve information of its screen shape from a server or something like that.
The only necessary information the server needs to store is the radius of the corner. If its 0, means the screen is a rectangle, otherwise the screen is rounded with the given radius r:
Having this information, you can pass it to a post processing shader that will evaluate the minimum distance from each pixel to the corner of the screen, and if this distance is less than some value you defined, you can paint it differently.
How can I prevent a WinForms Chart object from autosizing on the X axis when a new tickmark comes up?
A picture, or in this case a gif, is worth a thousand words:
See the little jump when a new gridline, tick, and label show up? Super annoying.
I'm pretty sure that the setting is somewhere in chart1.ChartAreas[0].AxisX but I haven't been able to find anything that prevents this from happening.
Where should I look?
When adding points at some point a new axis label must be added at each new interval. Since it is drawn centered at the value the chart needs to make room for it to both sides. The extra room to the right side then takes a while to be filled with data. This results in the jumps..
In my test the most straightforward solution was to simply omit the last axis label:
Axis ax = chart1.ChartAreas[0].AxisX;
ax.LabelStyle.IsEndLabelVisible = false;
Of course turning it back on when no more points are being added is a good idea.
Another, much more involved solution might be to disable the axis labels altogether and draw them in a xxxPaint event..
I'm working on a Winforms app that contains a large map image (5500px by 2500px). I've set it up so the map starts in full size, but the user can zoom out to a few different scales to see more of the map. The user is able to drag the map around to shift what they are looking at (like Google Maps, Bing Maps, Civilization, etc.).
When the map is full sized (scale = 1.0), I am able to prevent the user from scrolling past the borders of the image. I do this by calculating if they are trying to move past 0, or past the image width - current window size, similar to this:
if (_currHScroll <= 0) {
_currHScroll = 0;
}
This all works just fine. But, when I zoom out on the map (thus, making the image smaller), the limits for the bottom and right of the map break down. I know why this happens--because the Transform that is performed basically "compresses" the map a little bit, and so what used to be a 5000 px image is now smaller, depending on the scale. But, my limiters are based on the image size.
So, the user can scroll past the end of the map, and just sees white space. Worse things happen, I realize, but if possible I'd like to keep them from doing that.
I'm sure there is a straight-forward way to do this, but I haven't figured it out yet. I've tried simply multiplying my calculation by the scale, but that didn't seem to work (seems to under-estimate the size initially, then over-estimate on the smallest sizes). I've tried calculating the transform location of the bottom right of the image, and using that, but it turns out, that number is inverted, and I can't find what it relates to.
I'm including my transform point method here. It works just fine. It tells me, regardless of zoom level, what pixel was clicked on the original image. Thus, if someone clicks on point 200, 200 but the image is scaled at .5, it will show something like 400,400 as what was clicked (but, as I said, I don't think the scale value is a multiplier--using this just for demonstration purposes).
public Point GetTransformedPoint(Point mousePoint) {
Matrix clickTransform = _mapTransform.Clone();
Point[] xPoints = { new Point(mousePoint.X, mousePoint.Y) };
clickTransform.Invert();
clickTransform.TransformPoints(xPoints);
Debug.Print("Orig: {0}, {1} -- Trans: {2}, {3}", mousePoint.X, mousePoint.Y, xPoints[0].X, xPoints[0].Y);
return xPoints[0];
}
Many thanks in advance. I'm sure it's something relatively easy that I'm overlooking, but after several hours, I'm just not finding it.
If i understand right, you can calculate the maximum with your method GetTransformedPoint by using width and height from your Image as Point. The result can then be used inside your check...
And by the way, you are right, the scale value is a multiplier used as a factor. The only thing is, you have to cast the result to an integer.
I have a Y-Axis Label as shown here:
I am trying to position the label closer to the chart, is there any facility to do this?
I could add a Winforms Label and position it accordingly but just in case there is a better way.
If you are talking about the AxisY.Title AvGkW you can't position it other than aligning it near, center, far.
But you can add as many Titles to your Chart as you want, dock them to all four corners of the earth, um, Chart, style them and set their offset..
After you have added your Title like this:
Title TT = new Title( yourTitleText, Docking.Left, yourFont, yourcolor);
TT.Docking = Docking.Left;
yourChart.Titles.Add(TT);
You can move it left and right like this:
TT.DockingOffset = yourOffset;
It isn't in the specs here on MSDN but as usual it is in 1/100 of the Chart.Size, so setting it to 50 moves the Title into the middle of the ChartArea.. It is an int32 strangely!
You will have to play with the number depending on the size of the Y-Labels and the position of the Y-Axis. Values of 2-7 are OK here..
I'm asking a question here cause I'm not sure how to search it in google, I don't know the word how to call this.
What I mean is a "zero point" which basically located at upper-left corner of the element, pictureBox for an example. So when I set new width and height properties for my pictureBox it works fine but it's relative to top left corner.
What I mean is you've got pictureBox, let's say 100 x 100 and you desire decrease it to 50 x 100, so you will get "empty space" under your picture box, not upper. PictureBox counts it's properties from this one top left corner zero point.
And what I need is to change this point to the another corner.
So when I change my height it count up, not down. Help me please.
I really hope you can understand me.
Wow, thank you guys for your advices! I've tested anchor property and Top += 50; now, doesn't solve my problem. Let me try to describe it another way. You have an image (100px) with grass 50px at bottom and sky 50px at the top. So you have picturebox with height 100. If you set pictureBox.height = 50; you will see only sky. But I need to leave only grass. The main problem I see here is because this zero point at top left corner.
Here is an example:
Button1 click event:
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Height = 150;
}
The result which you will get after you press the button:
But I need another result:
As I understand it happens because height property counts from the top left corner. So if I change it to bottom left or right corner it will works the way I need. Help me please to change this point...
MSDN reference: http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.sizemode(v=vs.71).aspx
Valid values for this property are taken from the PictureBoxSizeMode enumeration. By default, in PictureBoxSizeMode.Normal mode, the Image is placed in the upper left corner of the PictureBox, and any part of the image too big for the PictureBox is clipped. Using the PictureBoxSizeMode.StretchImage value causes the image to stretch to fit the PictureBox.
Unless you are using a container which handles control layout automatically, you will have to move it yourself. I assume you are resizing the control in code with a line like:
myPictureBox.Height = 50;
You will have to also move the control's location down by the same amount:
myPictureBox.Top += 50;
Generalizing, something like this ought to do the trick for resizing height:
void ResizeHeightFromBottom(this Control c, int newHeight)
{
var oldBottom = c.Bottom;
c.Height = newHeight;
c.Top = oldBottom - newHeight;
}
I will leave resizing the width and both simultaneously as an exercise for the reader, as well as specifying an arbitrary reference point.