hello,
I am trying to do the following:
On load, a form must scale itself with a number of pixels on the X axis, lets say 100 pixels for example. Also it must do this on a timer, to ensure a somehow smooth animation.
How would I do this?> Here is what I wrote so far but it does not work. -
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
using System.Drawing.Drawing2D;
-
-
namespace drawingStuff
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
this.DoubleBuffered = true;
-
tmRefresh.Interval = 1;
-
}
-
private void Form1_Load(object sender, EventArgs e)
-
{
-
tmRefresh.Start();
-
}
-
-
private void tmRefresh_Tick(object sender, EventArgs e)
-
{
-
this.Invalidate();
-
}
-
-
-
private void Form1_Paint(object sender, PaintEventArgs e)
-
{
-
Graphics g;
-
g = e.Graphics;
-
g.SmoothingMode = SmoothingMode.HighQuality;
-
g.ScaleTransform(this.Width - 50, this.Height - 50);
-
-
Rectangle recForm = new Rectangle(0, 0, this.Width, this.Height);
-
Pen pen = new Pen(Color.Black);
-
g.DrawRectangle(pen, recForm);
-
}
-
-
}
-
}
-
Ok so what this does , it draws a rectangle inside my form. That one is scaled. I dont need rectangles inside my form, I want to scale the form itself and I don't know how to do this.
Please help with suggestions.
Regards,
7 5305
hello,
I am trying to do the following:
On load, a form must scale itself with a number of pixels on the X axis, lets say 100 pixels for example. Also it must do this on a timer, to ensure a somehow smooth animation.
How would I do this?> Here is what I wrote so far but it does not work. -
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
using System.Drawing.Drawing2D;
-
-
namespace drawingStuff
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
this.DoubleBuffered = true;
-
tmRefresh.Interval = 1;
-
}
-
private void Form1_Load(object sender, EventArgs e)
-
{
-
tmRefresh.Start();
-
}
-
-
private void tmRefresh_Tick(object sender, EventArgs e)
-
{
-
this.Invalidate();
-
}
-
-
-
private void Form1_Paint(object sender, PaintEventArgs e)
-
{
-
Graphics g;
-
g = e.Graphics;
-
g.SmoothingMode = SmoothingMode.HighQuality;
-
g.ScaleTransform(this.Width - 50, this.Height - 50);
-
-
Rectangle recForm = new Rectangle(0, 0, this.Width, this.Height);
-
Pen pen = new Pen(Color.Black);
-
g.DrawRectangle(pen, recForm);
-
}
-
-
}
-
}
-
Ok so what this does , it draws a rectangle inside my form. That one is scaled. I dont need rectangles inside my form, I want to scale the form itself and I don't know how to do this.
Please help with suggestions.
Regards,
If you want to modify items such as the form's size by timer you'll have to do it through the threading model using delegates.
VB -
-
Dim FinalSize As New System.Drawing.Size(400, 400)
-
Private WithEvents ChangeSizeTimer As New Timers.Timer(25)
-
Public Delegate Sub ChangeSizeDelegate(ByVal Size As System.Drawing.Size)
-
Public Sub ChangeSize(ByVal Size As System.Drawing.Size)
-
If Me.InvokeRequired Then
-
Me.Invoke(New ChangeSizeDelegate(AddressOf ChangeSize), Size)
-
Else
-
Me.Size = Size
-
End If
-
End Sub
-
Public Sub TimerEvt(ByVal Sender As Object, ByVal e As Timers.ElapsedEventArgs) _
-
Handles ChangeSizeTimer.Elapsed
-
Dim oSize As System.Drawing.Size
-
'Do whatever it is you have to do to calculate your next size
-
ChangeSize(oSize)
-
End Sub
-
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
Me.Size = New System.Drawing.Size(200, 200)
-
ChangeSizeTimer.Start()
-
End Sub
-
C# -
-
System.Drawing.Size FinalSize = new System.Drawing.Size(400, 400);
-
private Timers.Timer ChangeSizeTimer = new Timers.Timer(25);
-
public delegate void ChangeSizeDelegate(System.Drawing.Size Size);
-
public void ChangeSize(System.Drawing.Size Size){
-
if (this.InvokeRequired) {
-
this.Invoke(new ChangeSizeDelegate(ChangeSize), Size);
-
}
-
else {
-
this.Size = Size;
-
}
-
}
-
public void TimerEvt(object Sender, Timers.ElapsedEventArgs e) {
-
System.Drawing.Size oSize;
-
//Do whatever it is you have to do to calculate your next size
-
ChangeSize(oSize);
-
}
-
private void Form1_Load(object sender, System.EventArgs e) {
-
this.Size = new System.Drawing.Size(200, 200);
-
ChangeSizeTimer.Start();
-
}
-
I'll leave you to calculate the sizes...just use a basic calculation to determine if your form has reached the right size or not. When it does, kill the timer.
excellent! thank you very much for this, I am trying it now.
I dont understand this.
It never enters the TimerEvt() method, therefore it never enters ChangeSize() method.
What event do I need to set for it to work?
All it does is it enters Form_Load and thats it.
later edit:
ok I added an event now.
It does not work. Here is the code as it is now: -
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
using System.Diagnostics;
-
-
-
namespace diagnostics
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
changeSizeTimer.Elapsed += new System.Timers.ElapsedEventHandler(changeSizeTimer_Elapsed);
-
}
-
-
void changeSizeTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
-
{
-
System.Drawing.Size oSize;
-
oSize = this.Size;
-
if (finalSize == oSize)
-
{
-
changeSizeTimer.Stop();
-
}
-
changeSize(oSize);
-
}
-
-
Size finalSize = new Size(400, 400);
-
private System.Timers.Timer changeSizeTimer = new System.Timers.Timer(25);
-
-
public delegate void changeSizeDelegate(Size Size);
-
-
public void changeSize(Size Size)
-
{
-
if (this.InvokeRequired)
-
{
-
this.Invoke(new changeSizeDelegate(changeSize), Size);
-
}
-
else
-
{
-
this.Size = Size;
-
}
-
}
-
-
private void Form1_Load(object sender, EventArgs e)
-
{
-
this.Size = new System.Drawing.Size(200, 200);
-
changeSizeTimer.Start();
-
}
-
-
}
-
}
-
I dont understand this.
It never enters the TimerEvt() method, therefore it never enters ChangeSize() method.
What event do I need to set for it to work?
All it does is it enters Form_Load and thats it.
later edit:
ok I added an event now.
It does not work. Here is the code as it is now: -
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
using System.Diagnostics;
-
-
-
namespace diagnostics
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
changeSizeTimer.Elapsed += new System.Timers.ElapsedEventHandler(changeSizeTimer_Elapsed);
-
}
-
-
void changeSizeTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
-
{
-
System.Drawing.Size oSize;
-
oSize = this.Size;
-
if (finalSize == oSize)
-
{
-
changeSizeTimer.Stop();
-
}
-
changeSize(oSize);
-
}
-
-
Size finalSize = new Size(400, 400);
-
private System.Timers.Timer changeSizeTimer = new System.Timers.Timer(25);
-
-
public delegate void changeSizeDelegate(Size Size);
-
-
public void changeSize(Size Size)
-
{
-
if (this.InvokeRequired)
-
{
-
this.Invoke(new changeSizeDelegate(changeSize), Size);
-
}
-
else
-
{
-
this.Size = Size;
-
}
-
}
-
-
private void Form1_Load(object sender, EventArgs e)
-
{
-
this.Size = new System.Drawing.Size(200, 200);
-
changeSizeTimer.Start();
-
}
-
-
}
-
}
-
Did you get this working yet? The code you posted looks okay at first glance. Don't want to waste time trying to figure out something you already fixed. Cheers.
Make sure that the timer is enabled (by default it is set as false ie not enabled) which can cause some headache
thank you for your input, both of you.
It is not working yet but I am trying to figure out why I m sure its something small that I am missing :)
Thank you again.
thank you for your input, both of you.
It is not working yet but I am trying to figure out why I m sure its something small that I am missing :)
Thank you again.
Not that there's anything wrong with it that I can see...but try changing the names of your Size parameters...ma ybe that's causing a hiccup. I know that this functionality is supposed to be allowed, but I've had mixed success with calling objects by their typename, so now I try not to.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: News Central |
last post by:
I resize a control in a Form wth Scale mode set to vbInches. However, the
control's size changes in different screen resolution, I thought that if
Scale mode is set to vbInchs, then the control should have the same size
regardless of screen resolution... can anyone tell me why? thanks :>
|
by: Andrea Griffini |
last post by:
I did it.
I proposed python as the main language for our next CAD/CAM
software because I think that it has all the potential needed
for it. I'm not sure yet if the decision will get through, but
something I'll need in this case is some experience-based set
of rules about how to use python in this context.
For example... is defining...
|
by: S. van Beek |
last post by:
Dear reader,
A Microsoft Graph 2000 chart is as OLE class available in a form.
If the form opens a diagram will be produced.
Because of the variation in the figures for these diagrams the axis has to
be changed manually by double click the axis.
|
by: Frank |
last post by:
Hi,
I use form.scale to scale up/down my form and controls, works great.But...
when sizing in and the form and controls become bigger, at a certain moment
the form will be as big/bigger than the screendimensions.
It accounts for that, the window does not grow bigger but the controls do,
although the maximum window dimensions it uses is...
|
by: placid |
last post by:
Hi all,
I was just wondering what is the equivalent of Form1.Scale (-160,
-160)-(90, 95) in VB.NET?
The Form1.Scale(...) in the VB.net is not the same as the old VB!
Thanks in advance
| |
by: Jerry Spence1 |
last post by:
A very useful feature was added in 2.0 of .NET framework which was the
scaling of a form and all the controls within it. This is really useful but
I am finding very little information of how to use it.
I have managed to implement it as follows:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles...
|
by: TonyJ |
last post by:
Hello!
We have a pc running a form application.
If I push some buttons in this application I want to send some commands to a
scale which is connected
to a specific IP address. When I sent a command I also receive an answer
from the scale.
I want to communicate with the scale using TCP or UDP.
The commands that can be sent to the scale are...
|
by: Wagsy |
last post by:
Hi All,
I have a small form that allows scale weigh data to be diplayed in a textbox. i can communicate with the scale - tare, zero etc.
how do i filter the weight string or i think it may be called parsing? i'll try to explain: currently i can have the scale sending continuous weight data, but i can also set it to print every secon or so,...
|
by: Maria DiGiano |
last post by:
I am using Access to organize data from a survey which uses a Likert
scale to measure response- the scale is 3 points- "I agree", "I don't
know" and "I disagree". The numerical value of each response (1, 2 or
3) varies- such that for some questions "I agree" is = to 3 points,
and other times "I agree" is = to 1. I created an "answer key"...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |