|
yes, it's written in closed event in a different solution..
|
|
|
|
|
I have an that on startup I want the main form to be hidden and activated from System Tray on Click. It works but the main form is always visible on startup????
Any help appreciated
Mike
|
|
|
|
|
Can be accessed to visible property from properties window in design view
|
|
|
|
|
Form properties does not contain a visible property but I tried all the basic stuff Hide(), visible = false in the _Load event but for some reason doesn't work. Even tried creating ApplicationContext.MainForm.visible = false in Main()???
private void Form1_Load(object sender, System.EventArgs e)
{
Rectangle rct = Screen.PrimaryScreen.WorkingArea;
Point pt = new Point(rct.Width - this.Width, 0);
this.Location = pt;
notifyIcon1.Visible = true;
this.Hide();
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
notifyIcon1.Visible = false;
}
private static bool isVisible = false;
private void notifyIcon1_Click(object sender, System.EventArgs e)
{
if (isVisible)
{
this.Visible = false;
isVisible = false;
}
else
{
this.Visible = true;
isVisible = true;
}
}
Thanks
|
|
|
|
|
Any code remain in designer.cs; for example a visible property with true value?
|
|
|
|
|
NO here is the InitializeComponent properties for Form1
//
// Form1
//
this.AutoScale = false;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(162, 511);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Contact Manager";
this.TopMost = true;
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
this.Load += new System.EventHandler(this.Form1_Load);
???
Mike
|
|
|
|
|
In your form's constructor write this line
this.Visible = false;
Regards
|
|
|
|
|
|
Fine. Put the same line of code in the Form.Shown event handler. You have to handle the event first of course, and it's present only in DotNet 2.0. If you use older versions you can use the Paint method instead and make a flag whether you want to hide or not.
Regards
|
|
|
|
|
That worked but the form came up then went invisible?
Any insight into how I can keep it from coming up in 1st place?
Thanks all for your help
Mike
|
|
|
|
|
Alright. I got a much better idea. Simply in the designer or in the constructor set the Form's Opacity to 0 (Zero). This way it will never show up.
Regards
|
|
|
|
|
I had thought of that but seemed kludgy. But looks like that may be the only answer!
Thank you all for your input and help. I hope I can return the info in the future.
Regards
Mike
|
|
|
|
|
Have you tried making the opacity of the form 0? and then when the system tray is clicked the opacity is 100? And then you could make it slowly fade in for a cool effect.
|
|
|
|
|
I have this program I wrote that will search the entire c drive and make a treeview dialog of all the folders with the memory taken up by the folders. I can understand that this process should take up some memory, but once it finishes it should release the memory because all you are doing now is looking at the treeview which has been all filled out already with all the information that it will ever have.
I guess I'm trying to say that once the dialog comes up, how can I free some of the memory that my program has taken up? On my machine it has taken up to 30k of memory, and held it until I close it.
Here is the code. Thanks in advance for any help. If this is too much code, let me know and I will edit my post.
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace MemoryManagmentDialog
{
/// <summary>
/// Description of MainForm.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TreeView treeView1;
public static double GetDirectorySize (DirectoryInfo Di, TreeNode ParentNode, bool IsFirst) {
double DirSize = 0;
try {
FileInfo[] fiAr = Di.GetFiles ();
foreach (FileInfo fi in fiAr) {
DirSize = DirSize + fi.Length;
}
DirectoryInfo[] diAr = Di.GetDirectories();
if (IsFirst == true) {
foreach (DirectoryInfo di in diAr) {
DirSize = DirSize + GetDirectorySize (di, ParentNode, false);
}
}
else {
TreeNode SubNode = new TreeNode (Di.Name);
foreach (DirectoryInfo di in diAr) {
DirSize = DirSize + GetDirectorySize (di, SubNode, false);
}
ParentNode.Nodes.Add (SubNode);
SubNode.Text = Di.Name + " - [ " + SizeToString (DirSize, SubNode) + " ]";
}
}
catch {
TreeNode SubNode = new TreeNode (Di.Name);
ParentNode.Nodes.Add (SubNode);
SubNode.Text = Di.Name + " ** [ Error ]";
SubNode.BackColor = Color.Red;
SubNode.ForeColor = Color.White;
}
return DirSize;
}
public static string SizeToString (Double dbl, TreeNode tn) {
string Str;
if (0 <= dbl && dbl < 1000) {
Str = dbl.ToString() + " b";
tn.BackColor = Color.Orange;
return Str;
}
else if (1000 < dbl && dbl < 1000000) {
Str = (dbl / 1000).ToString() + " KB";
tn.BackColor = Color.PaleGreen;
return Str;
}
else if (1000000 < dbl && dbl < 1000000000) {
Str = (dbl / 1000000).ToString() + " MB";
tn.BackColor = Color.DeepSkyBlue;
return Str;
}
else {
Str = (dbl / 1000000000).ToString() + " GB";
tn.BackColor = Color.White;
return Str;
}
}
void MainFormLoad (object sender, System.EventArgs e) {
DirectoryInfo di = new DirectoryInfo (@"c:\");
TreeNode MainNode = new TreeNode (di.Name);
treeView1.Nodes.Add (MainNode);
double MainSize = GetDirectorySize (di, MainNode, true);
MainNode.Text = di.Name + " - [ " + SizeToString (MainSize, MainNode) + " ]";
}
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void Button1Click(object sender, System.EventArgs e)
{
Close();
}
[STAThread]
public static void Main(string[] args)
{
Application.Run(new MainForm());
}
#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent()
{
this.treeView1 = new System.Windows.Forms.TreeView();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// treeView1
//
this.treeView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.treeView1.ImageIndex = -1;
this.treeView1.Location = new System.Drawing.Point(0, 0);
this.treeView1.Name = "treeView1";
this.treeView1.SelectedImageIndex = -1;
this.treeView1.Size = new System.Drawing.Size(512, 280);
this.treeView1.TabIndex = 1;
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.button1.Location = new System.Drawing.Point(420, 287);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Done";
this.button1.Click += new System.EventHandler(this.Button1Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.treeView1);
this.Controls.Add(this.button1);
this.DockPadding.All = 1;
this.MinimumSize = new System.Drawing.Size(250, 340);
this.Text = "Folder Memory Sizes";
this.Name = "MainForm";
this.Load += new System.EventHandler(this.MainFormLoad);
this.ResumeLayout(false);
}
#endregion
}
}
Tim
|
|
|
|
|
T.Willey wrote: the treeview which has been all filled out already with all the information that it will ever have.
Sure! And where do you think this information is stored -for repainting, etc...- until the TreeView is disposed?
Regards
|
|
|
|
|
I was thinking that once it was done searching the drive then it wouldn't need to consume as much memory. If I'm wrong, then I think it will be fine, I was just trying to optomise it.
Thanks again Nader. I never did get the other program you were helping me with to work, and the person I was doing it for found another way, so I stopped trying after like 7 revisions.
Tim
|
|
|
|
|
T.Willey wrote: I never did get the other program you were helping me with to work
That's bad news!! I hope you make it next time. Best wishes, and you are welcome anytime.
Regards
|
|
|
|
|
In .NET you typically dont have to worry continuously about memory consumption;
objects that are in use normally stay alive, and objects that are not needed anymore,
although not deleted immediately (as would be the case with unmanaged C++ destructors),
get discarded when the garbage collector sees fit.
Also 30KB is a really small amount on most of todays systems.
It still pays off to keep memory consumption in mind when performance is important,
so one should avoid making an excessive number of objects.
I see no problems with your application; there are some strings (as in all apps),
and the FileInfo and DirectoryInfo arrays go out of scope pretty soon, so they
are collectable.
If you want to save memory, you can:
- empty collections (e.g. ListView.Clear)
- set unneeded object references to null (so they become collectible even before
they go out of scope).
Both of these of course only if your program logic allows it.
As a last resort, you could invoke the garbage collector explicitly, but in
general, this is not a good thing to do. Normally just let it do it's thing...
Luc Pattyn
|
|
|
|
|
Thanks for the heads up Luc. I write C# very infrequent, so these are nice tips to know.
Tim
|
|
|
|
|
HI,
With the try,catch and throw you can also use "finally" and within the finally block you can release the resources that have occupied memory.
thanks,
vikram
Vicky
|
|
|
|
|
I am programatically adding items to the ListView Control. I also want to programatically scroll to the last item in the control...how do i do this?
|
|
|
|
|
try ListView.EnsureVisible()
Luc Pattyn
|
|
|
|
|
Thank You so much!
|
|
|
|
|
Hey guys,
I need to hide the VS Report (.rdlc files) print window dialog when printing (that one that shows "printing page X of Y", or something), like a silent mode. Is there any way to accomplish it? I think there's not any silent mode in this component, so i think i'll need to tweak it a little.
I'm printing a lot of reports at the same time and a lot of these windows appears to our users - and no, they don't like it. XD
Thanks for your attention...
bad, bad engRish... :/
|
|
|
|
|
First of all, thx for your replies. And sry about my broken english. I'm still noob . But that's not my homework but a problem i wanna solve. Till now i cant find the solution. Let me make it more clearly:
1) The site i tested is: www.ou.edu.vn/diemthi. U can log onto it to check it. There are 2 textbox: ID and password. ID and password are alike for example 10300005. So i wanna build a program that inserts the ID & password automatically and submit it. The ID can be inserted from x to y such as 10300005 -> 10300008 one by one. Is there anyway i can solve this?
2) Once u click the submit button, the mark page occurs. It has a table which contains the student's marks. And i wanna get those marks to add them into my database but i dont know how. I searched in the MSDN and many e-books but still cant find any object or function that can solve it.
Any ideas for me ?
|
|
|
|