Scaling a Picture Box
Scaling a Picture Box
Scaling a Picture Box
Scaling a Picture Box
Scaling a Picture Box
Scaling a Picture Box Scaling a Picture Box Scaling a Picture Box Scaling a Picture Box Scaling a Picture Box Scaling a Picture Box Scaling a Picture Box Scaling a Picture Box
Scaling a Picture Box Scaling a Picture Box
Scaling a Picture Box
Go Back  Xtreme Visual Basic Talk > > > Scaling a Picture Box


Reply
 
Thread Tools Display Modes
  #1  
Old 01-08-2013, 07:02 AM
jotol jotol is offline
Newcomer
 
Join Date: Nov 2012
Posts: 5
Default Scaling a Picture Box


Hi,
Iam new to .net. Iam trying to make and aplication where I have a picture box that acts as a analog meter with the nidle at the center. now What a want to do is scale the picturebox so that if I choose the meters parameter to be from 0 to 10 the center scele would be 5. In other words if I have a textbox and someone enters the value of 5 the nidle moves to the midle of the Picturebox. I have the nidle movement ok but I having a hard time scaling the picture box. in VB6 I use the Scale mode,scaleHigh,and scalewidth properties to do this.
or if anyone know a good tutorial o book for .net grphics programing.
Reply With Quote
  #2  
Old 01-08-2013, 10:43 AM
passel's Avatar
passelScaling a Picture Box passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

In .Net, the most likely way to do it would be using a matrix transform to change the Scale when you draw that portion. But depending on what you're doing, if it is just a matter of changing the coordinate scale of where you draw the needle, not the scale of the drawing itself, i.e. the needle doesn't get drawn bigger, or smaller, just where it is drawn, you may just want to calculate the coordinates yourself.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 01-08-2013, 11:30 AM
AtmaWeapon's Avatar
AtmaWeaponScaling a Picture Box AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

I'm not sure I understand why you need to scale an image. When I think of a meter, I'm thinking of a speedometer-like device. To draw that, I'd map the value to a percentage, apply that to the sweep arc of the meter, and use that to determine a rotation angle.

In short, your description of the solution and the problem don't match. What are you actually trying to do?
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #4  
Old 01-08-2013, 03:37 PM
passel's Avatar
passelScaling a Picture Box passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

In VB6, the scale properties of the Picturebox were used to provide different linear coordinate systems for your drawings.
So, in this case, I believe we're talking a straight gage, like some thermometers, as opposed to a circular gage.
And I can't tell by the description whether the needle should be vertical or horizontal (whether the gage scale is horizontal or vertical), but for illustration, assume a horizontal scale, with a vertical needle that would move left and right to indicate the value.
In VB6 and earlier, you could set ScaleLeft to 0 and ScaleWidth to 10 (and most likely not change the ScaleHeight dynamically as the needle is always the same length) and then if you drew a vertical line at an X value of 5, it would be in the middle of the picturebox.
If you changed ScaleWidth to 20 and redrew the line at 5, it would now be 25% from the left.
If you change the ScaleLeft to -5, then the line drawn at 5, it would be in the middle of the picturebox again (ScaleWidth is 20, so horizontal "scale" runs -5 to 15 across the picturebox).
The coordinate system in VB6 was always singles, and the mouse coordinates reported back in the mouse events are in the defined scale, so if you moved the mouse around the "needle", the X position would be reported as the floating point number 5.0 or in the neighborhood of 5.0, i.e. 4.95, 5.1, etc.
In VB6, changing the scale just changes the coordinate system, it doesn't affect the size of bitmaps drawn, or the thickness of "pens" used to draw the lines.

Since in .Net, the scale transforms do affect the thickness of pens, and the size of bitmaps drawn, most likely if you want to emulate what you did in VB6, you would not want to use the scale transforms, but just convert the values, essentially to a percentage as AtmaWeapon says.
For instance, if the picturebox was 400 pixels wide (client area width), and you wanted that to represent a scale of 0 to 10, you would set your "scalefactor" = "client width"/"scale width", i.e. 400/10 and use that as a multiplication factor to convert your scale coordinate into picturebox coordinate.
You would probably want to wrap the various drawing commands you need in subroutines that could apply the current scaling to the coordinates passed, so you wouldn't have the coordinate conversions spread thoughout the code.

Another option would be to set up a matrix to do the scale conversion, but rather than use the matix to transform the drawing, just use it to transform the coordinates by passing an array of coordinates (points) to the Transform method of the matrix and it will modify the points to be in the new scale, but if you're just beginning to use .Net, I think that would be a concept that is a little harder to grasp, then a simple scalefactor multiplication you write yourself.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 01-10-2013 at 10:09 AM.
Reply With Quote
  #5  
Old 01-08-2013, 08:41 PM
AtmaWeapon's Avatar
AtmaWeaponScaling a Picture Box AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

I'm pretty sure there's a way to muck about with the origin of the Graphics object as well so your coordinates or more convenient, but as close as I can come to discussing this without endangering breaking some of my contract terms is to say doing that conversion manually via percentages is a trick I use frequently.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #6  
Old 01-08-2013, 09:10 PM
jotol jotol is offline
Newcomer
 
Join Date: Nov 2012
Posts: 5
Default

Thank you atmaWeapon and passel for your reply.
But Iam still a little comfuse about how to scale
on vb.net do any of you know about a good book
or tutorial for biginers that I can read. The reason
is so important to me to scale a picturebox is becaufse
I need to work with small numbers such as .872 ml.
for example I I tes a unit and I get .675 the nidle will
show that Close the the range wish is not aceptable
is like a grphical representation of the value mesure
vs the value spected. Right now I can move the nidle
int the picturebox up or down but I cant format the
picturebox to have the values tha I need.

I have made a similar program in vb6 and it works fine but
I am having problems grasping the concep os scaling in .net.

thank you once more for your reply.
Reply With Quote
  #7  
Old 01-09-2013, 03:21 AM
hDC_0Scaling a Picture Box hDC_0 is offline
Contributor

* Expert *
 
Join Date: Feb 2004
Posts: 559
Default vb.net graphics - A good book, or a few good online tutorials, or some code examples

Quote:
Originally Posted by jotol
But I'm still a little comfuse about how to scale
on VB.Net
Do any of you know about a good book or tutorial for beginners that I can read?
Well..it seems like you in a mood to access some more resources regarding VB.Net graphics.

Since you are an old VB6-er you probably know the best book for VB6 Graphics was Ron Stephens' Visual Basic Graphics Programming.
Sad to say there is no VB.Net graphics book that has the breadth and scope of that book.

I found Eric White's Pro .NET 2.0 Graphics Programming book to be a pretty good read back in 2005.
This APress page for that book has a tab labelled "Source code downloads" that still has the code available for free download.

You also mentioned tutorials..
Here's a few online VB.Net Graphics tutorials to get you started:
CodeProject: Introduction to GDI+ in .NET
GDI+ Graphics in Visual Basic .NET
GDI+: Line-Based Shapes
.Net Heaven GDI+ IN VB.NET Articles

Sites that have some good VB.Net Graphics tips/tricks/code include:
The BobPowell site, including this page.
The VB.Net 2D graphics section of the java2s site
The VB.Net Graphics section of the vbHelper site

Of course if all else fails there is always MSDN.
Yes it can be rather dry and unexciting but there still is a lot of good info.
Some random pages:
Coordinate Systems and Transformations (Windows).
(Note: You might want to focus more on the Types of Coordinate Systems section and try not to
get too overwhelmed by the Matrix Representation of Transformations page).

The GDI+ section includes a "Lines, Curves, and Shapes" section as well as an "Overview of Vector Graphics" section.

If you downloaded the VB.Net 101 samples, the analog clock demo (see screenshot) might provide a helpful GDI-related code study.

You also might find a quick-n-dirty gauge example if you look around.

Last edited by hDC_0; 01-09-2013 at 04:02 AM.
Reply With Quote
  #8  
Old 01-09-2013, 05:13 AM
jotol jotol is offline
Newcomer
 
Join Date: Nov 2012
Posts: 5
Default

Thank you hDC o this information is very helpfulI will be looking into it
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Scaling a Picture Box
Scaling a Picture Box
Scaling a Picture Box Scaling a Picture Box
Scaling a Picture Box
Scaling a Picture Box
Scaling a Picture Box Scaling a Picture Box Scaling a Picture Box Scaling a Picture Box Scaling a Picture Box Scaling a Picture Box Scaling a Picture Box
Scaling a Picture Box
Scaling a Picture Box
 
Scaling a Picture Box
Scaling a Picture Box
 
-->