Scaling a Panel, formula issue - vb.net

I'm trying to scale a panel to fit it's parent panel, which I have accomplished By doing this:
ValSize = New Size(basePanel.Width - 20, basePanel.Height - 20)
This works well, but now I want to add another panel (dragItem) to this one I just scaled down (basePanel), but I need to keep the scaling the same between the 2 panels so they are not the same size but scaled the same mount. I was trying to use this formula to find how much I scaled the first item and get a percentage and use that for the new panel.
Dim scaleWidth As Double = Math.Abs(basePanel.Width - dragItem.Width) / dragItem.Width
Whats the proper way to do this?

If you want to get the ratio you are only supposed to divide.
Ratio of a smaller panel compared to the original:
Dim scaleWidth As Double = otherPanel.Width / basePanel.Width
Returns values <= 1
‌‌
Ratio of the original panel compared to a smaller:
Dim scaleWidth As Double = basePanel.Width / otherPanel.Width
Returns values >= 1
So if you have a panel that is 200px wide and a smaller one that is 150px wide, the ratio will be 0.75. To create a new panel from this based on the smaller panel you would do:
Dim newWidth As Integer = scaleWidth * otherPanel.Width
Since scaleWidth is 0.75 and otherPanel.Width is 150, you will get the following result: 0.75 * 150 = 113 (112,5 to be exact, but it's rounded since it's an integer).
Now your third panel will be 25% smaller than the second panel. The second panel in turn is 25% smaller than the original panel.

Although it's possible, you don't need to do this calculations by yourself. Instead, set each panel's dock property to Fill and set the padding of the container as you like. In this case it's seems to want equal padding for every container.

Related

Stop .Net Chart (DataVisualization) From ReSizing To Tiny Chart?

I have a chart that has strings for its x axis (a list of names). It's linked to a dynamic array, I have a problem where the graph resizes itself and squeezes 14-15 strings from the array and makes the bar chart small and tiny.
How can I achieve chunky bars and a scroll bar to scroll down to see the rest of the data even when new values are being added to the x-axis at runtime.
Have spent an hour searching with no help! =[
Edit:
Setting the PixelPointWidth Property to 300 gave me the width of the bar the way I want to be, but it has bunched the bars so that all the bars of the 4 series are overlapping instead of being side by side. WHere to go from here?
Edit2:
Manipulating the charts height is definitely getting the desired results, the only thing is the bigger the height, the more white space at the top of the chart, whats the fix for that,. and a fix for the Series representations to be "frozen" on scroll.
You can set the width of the chart every time you add new data to it:
Dim barWidth = Double.Parse(Chart1.Series(0)("PixelPointWidth"))
Chart1.Width = CInt(nData * barWidth) + 100
where nData is how many points there are and the 100 is some amount to take into account the space needed for the Y-axis labels and the legend.
Place the chart control in a Panel as suggested by jmcilhinney with AutoScroll set to true, and you will get a scrollbar when the width of the chart exceeds the width of the panel.
If you want the chart to show the latest added data, you can set the horizontal scroll position after setting the width of the chart:
Panel1.HorizontalScroll.Value = Panel1.HorizontalScroll.Maximum

PyGObject: How to do a Grid

Ok, I have a ScrolledWindow with inside a Viewport and a Fixed inside of that. I'm using the Builder so I'm not gonna post ALL the code if is not necessary.
I'm using a function that multiplies the given coordinates per 50, so i have a grid with 50 x 50 pixel's squares (the number of squares can variate in the config).
The real question is very simple, how I can put a background of a grid of 50 per 50 pixels? And that should be """infinite""". Preferly the lines should be of 1 px.
Note: I'm not using a grid because I need only to put Images or Icons
I used that. Mainport is the fixed element, and wres and hres are the number of squares
for i in range(self.wres):
image = gtk.Image.new_from_file("resources/Back.png")
self.mainport.put(image, i*50, 0)
for z in range(self.hres):
image2 = gtk.Image.new_from_file("resources/Back.png")
self.mainport.put(image2, i*50, z*50)

Resize image and keep aspect ratio

I'm trying to make zoom in/out buttons, but for whatever reason I just can't figure out how to maintain the aspect ratio and resize the image by - say 90% or 110%
The issue is that I'm trying to make it so that when you click the zoom out button 4 times, then click the zoom in button 4 times, the image would be its original size. There's no defined width since I'm trying to make the new width be 90%/110% of the existing width, but obviously multiplying by 0.9 and 1.1 doesn't do that correctly.
I currently have the following code..
Dim source As New Bitmap(PictureBox1.Image)
Dim NewWidth As Integer = source.Width * 0.9
Dim NewHeight As Integer = NewWidth * (source.Height / source.Width)
Any help is appreciated. I'm sure I'm just over-thinking it again, but some guidance would be appreciated :)
The best approach is to begin each resize operation with a copy of the original image. Have your buttons represent the total zoom factor (so say add 0.1 zoom for the + and subtract 0.1 zoom for the -).
You want to start with the original image each time because otherwise successive operations will quickly distort the image due to the interpolation inherent in zooming in and out.

Quartz scaling sprite vertical range but not horizontal when go to fullscreen mode / increase window size

I have create a Quartz composition for use in MAC OS program as part of my interface.
I am relying on the fact that when you have composition sprite movement (a text bullet point in my case) is limited both in the X plane and Y plane to minimum -1 and maximum +1.
When I scale up the window / make my window full screen, I find that the horizontal plane (X axis) remains the same, with -1 being my far left point and +1 being my far right point. However the vertical plane (Y axis) changes, in full screen mode it goes from -0.7 to +0.7.
This scaling is screwing with my calculations. Is there anyway to get the application to keep the scale as -1 to +1 for both horizontal and vertical planes? Or is there a way of determining the upper and lower limits?
Appreciate any help/pointers
Quartz Composer viewer Y limits are usually -0.75 -> 0.75 but it's only a matter of aspect ratio. X limits are allways -1 -> 1, Y ones are dependents on them.
You might want to assign dynamically customs width and heigth variables, capturing the context bounds size. For example :
double myWidth = context.bounds.size.width;
double myHeight = context.bounds.size.height;
Where "context" is your viewer context object.
If you're working directly with the QC viewer : you should use the Rendering Destination Dimensions patch that will give you the width and the height. Divide Height by 2, then multiply the result by -1 to have the other side.

Make the X and Y axis scales equal on an Excel chart

I'd like the X and Y axes of my Excel charts to have the same scale on the screen, because I'm plotting geographical data. A 1km by 1km square should look like a square, not like a rectangle, i.e. no squishing of the map in one or the other direction. In Matlab, the command that would do this is axis equal.
How do I do this using VBA?
Am I overlooking an even simpler solution directly in Excel?
In addition to guitarthrower's answer you will need to do the following:
Select the 'Plot Area' of the chart and then manually set the height and width of the plot area.
Sheets("Chart1").PlotArea.Select
Selection.Height = 500
Selection.Width = 500
Just setting the axis min and max values will still allow the chart to be 'squished'.
When you select the plot area and write Selection.Width = something, the Width value you are setting also includes the width of the axis labels/text. This may not be what you want.
Instead, you can set the INSIDE Width/Height value using
Selection.InsideHeight = 250
Selection.InsideWidth = 250
Another method similar to Stewbob's is to set the limits to some ratio of each other (my plots are 4 times as wide as they are tall) and then use the height to set the width.
ActiveChart.PlotArea.Select
Selection.Width = Selection.Height * 4