943,152 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 1654
  • C# RSS
Jul 21st, 2008
0

Hight and Width Changes Problem

Expand Post »
Hello!

I have a problem with the size. I've made a function that saves the size, but each time I start the application does the size get larger then the last time. How do I fix that problem?

Here are the code for the function:
C# Syntax (Toggle Plain Text)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10.  
  11. namespace WindowsFormsApplication1
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18.  
  19. FileInfo FI1 = new FileInfo("Width.txt");
  20. FileInfo FI2 = new FileInfo("Height.txt");
  21.  
  22. if (!FI1.Exists)
  23. {
  24. StreamWriter SW = new StreamWriter("Width.txt");
  25. SW.Write(this.Size.Width);
  26. SW.Close();
  27. }
  28.  
  29. if (!FI2.Exists)
  30. {
  31. StreamWriter SW = new StreamWriter("Height.txt");
  32. SW.Write(this.Size.Height);
  33. SW.Close();
  34. }
  35.  
  36. StreamReader SR1 = new StreamReader("Width.txt");
  37. StreamReader SR2 = new StreamReader("Height.txt");
  38. TextBox TB1 = new TextBox();
  39. TextBox TB2 = new TextBox();
  40. TB1.Text = SR1.ReadLine();
  41. TB2.Text = SR2.ReadLine();
  42. SR1.Close();
  43. SR2.Close();
  44. this.ClientSize = new Size(Convert.ToInt32(TB1.Text), Convert.ToInt32(TB2.Text));
  45. }
  46.  
  47. private void Form1_SizeChanged(object sender, EventArgs e)
  48. {
  49. if (this.WindowState != FormWindowState.Maximized)
  50. {
  51. StreamWriter SW1 = new StreamWriter("Width.txt");
  52. StreamWriter SW2 = new StreamWriter("Height.txt");
  53. SW1.Write(this.Size.Width);
  54. SW2.Write(this.Size.Height);
  55. SW1.Close();
  56. SW2.Close();
  57. }
  58. }
  59. }
  60. }
Attached Thumbnails
Click image for larger version

Name:	HightChange.jpg
Views:	161
Size:	8.2 KB
ID:	6710  
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
FullBjarne is offline Offline
9 posts
since Jul 2008
Jul 22nd, 2008
0

Re: Hight and Width Changes Problem

I think I solved the problem my self.
I change this code:
C# Syntax (Toggle Plain Text)
  1. this.ClientSize = new Size(Convert.ToInt32(TB1.Text), Convert.ToInt32(TB2.Text));
to:
C# Syntax (Toggle Plain Text)
  1. this.ClientSize = new Size(Convert.ToInt32(TB1.Text) - 37, Convert.ToInt32(TB2.Text) - 37);
But I'm not sure if - 37 is the exact right number.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
FullBjarne is offline Offline
9 posts
since Jul 2008
Jul 22nd, 2008
0

Re: Hight and Width Changes Problem

My friend,

Is this all the code that access the files Width.txt and Height.txt?
Reputation Points: 10
Solved Threads: 3
Light Poster
AmirBedair is offline Offline
26 posts
since Jul 2008
Jul 22nd, 2008
0

Re: Hight and Width Changes Problem

My friend,

Height - 34
and width - 8

use the next method to indicate the increase value of the width and hieght just opne and close the window without any change in the size, you will know the increased pixels
C# Syntax (Toggle Plain Text)
  1. protected override void OnClosing(CancelEventArgs e)
  2. {
  3. StreamWriter SW1 = new StreamWriter("Width.txt");
  4. StreamWriter SW2 = new StreamWriter("Height.txt");
  5. SW1.Write(this.Size.Width);
  6. SW2.Write(this.Size.Height);
  7. SW1.Close();
  8. SW2.Close();
  9.  
  10. base.OnClosing(e);
  11. }
Reputation Points: 10
Solved Threads: 3
Light Poster
AmirBedair is offline Offline
26 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
Next Thread in C# Forum Timeline: varaint string





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC