|
You can use the Form's ClientSize property to achieve this.
Form.ClientSize = Image.Size;
From the MSDN docs:
Form.ClientSize Property - Gets or sets the size of the client area of the form. The size of the client area of the form is the size of the form excluding the borders and the title bar. The client area of a form is the area within a form where controls can be placed. You can use this property to get the proper dimensions when performing graphics operations or when sizing and positioning controls on the form. To get the size of the entire form, use the Size property or use the individual properties Height and Width
"I think I speak on behalf of everyone here when I say huh?" - Buffy
|
|
|
|
|
Do updating Form.ClientSize updates Form.Size too?
|
|
|
|
|
Yup, and vice-versa
It makes sense to only work using the ClientSize and forget about the form's actual size, since that way it'll automatically work on different configurations (think of the difference in titlebar size on XP to other versions of windows)
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
I have another question on that metter:
I need to change the size of the window.
currently I'm working with sizable window border style
and it doesn't allow me to change the width less then 104 pixles. this number 104 might change in different Windows system (2000 or xp).
Does anyone know where this number came from?
Thank you in advance,
Anna.
|
|
|
|
|
Take a look at the System.Windows.Forms.SystemInformation class. The value is specified in the MinimumWindowSize property (on xp its 123 x 34)
"I think I speak on behalf of everyone here when I say huh?" - Buffy
|
|
|
|
|
Hi,
I have a Library DLL that is used by a .NET Web application (running in Windows 2003 server). The DLL / Library will try to send some data to two web application (ASP running on windows 2000 server) running on two different servers.
If the any of the Windows 2000 server is down the .Net Web application fails to complete the request. It is understood that it should fail for the server which is down, but it also fails for the other server as well. And this does not fail always it fails only some times.
The DLL is written in C#. The function that sends the webrequest creates a HttpWebRequest object using the WebRequest.Create method
and times out for the method call for HttpWebRequest.getResponse().
I am not setting the no-cache to the headers and also not setting proxy properties.
Please the function that is being used for this
HttpWebRequest HttpWReq;
HttpWebResponse HttpWResp = null;
StreamReader receiveStream = null;
Stream readStream = null;
int result =0;
try
{
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
HttpWReq =
(HttpWebRequest)WebRequest.Create("http://" + ip._ipAddress + ":" + ip._port + "/iPackagerweb/Upload.asp");
HttpWReq.KeepAlive = false;
HttpWReq.Timeout = _iPackTimeout;
String postData;// = "ID#~" + screenID;
if(screenID.Equals("shutdown"))
{
postData = "ID#~" + "update_" + screenID;
postData += "&~Update#~1" + "&~Data#~" + data;
}
else
{
postData = "ID#~" + screenID;
postData += "&~Update#~0" + "&~Data#~" + data;
}
HttpWReq.Method = "POST";
HttpWReq.ContentType="application/x-www-form-urlencoded";
HttpWReq.ContentType="multipart/form-data";
HttpWReq.ContentLength = postData.Length;
//ASCIIEncoding asciiEncoding = new ASCIIEncoding();
Stream data2Send = HttpWReq.GetRequestStream();
byte[] postByteData = encode.GetBytes(postData);
data2Send.Write(postByteData, 0, postData.Length);
data2Send.Close();
HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
readStream = HttpWResp.GetResponseStream();
receiveStream = new StreamReader(readStream, encode, false);
if(receiveStream != null)
{
Char [] strResp = new Char[255];
String resultMessage = "";
int count = receiveStream.Read(strResp, 0, 255);
while(count > 0)
{
resultMessage += new String(strResp, 0, count);
count = receiveStream.Read(strResp, 0, 255);
}
if(resultMessage != null || resultMessage.Length == 0)
{
;
}
else
{
HttpWResp.Close();
HttpWResp = null;
receiveStream.Close();
receiveStream = null;
readStream.Close();
readStream = null;
result = 3;
errMessage[0] = resultMessage;
return result;
}
receiveStream.Close();
receiveStream = null;
}
else
{
HttpWResp.Close();
HttpWResp = null;
result = 3;
return result;
}
HttpWResp.Close();
HttpWResp = null;
return result;
}
catch(WebException we)
{
//Logging exception here and found out to be timeout exception
}
catch(Exception e)
{
//Logging the exception here as well, does not come here
}
if(HttpWResp != null)
{
HttpWResp.Close();
HttpWResp =null;
}
if(receiveStream != null)
{
receiveStream.Close();
receiveStream = null;
}
if(readStream != null)
{
readStream.Close();
readStream = null;
}
return result;
Any help on this would be of great help. I have time till Dec 16 (Thrusday after noon Sydney time)
Thanks in advance
|
|
|
|
|
Hi
I've created simple windows form application with two windows forms.
On each form IE WebControl is embeded.
I'am loading into IE control page with .Net applet with TextBox and CheckBox (IE is hosting .Net UserControl)
When the application starts I'm loading Form1. All is working fine. I can set focus to TextEdit and change state of CheckBox.
When I'm pressing a button on that form, Form2 loads.
When I'm trying to set focus to EditBox I have SecurityException.
When I click continue (not terminate), then select other window (Form2 must lost focus), then set focus to Form2, all works great, no security warning.
I'm working with default permission sets in .Net.
Why this is working in that way ?
Here is the sample application: http://www.abc.com.pl/download/test_ie.zip
I'm using: WinXP SP2, .Net 1.1 Sp1
Thx 4 Hlp
|
|
|
|
|
How can I track this thru programming?
|
|
|
|
|
Loads of them.
If you mean, how can I detect which service pack is installed, you should use the GetVersionEx[^] API with the OSVERSIONINFOEX[^] structure. Then examine the wServicePackMajor and wServicePackMinor values.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hey,
I am writing a console application, and doing a lot of console.writeline() (s),
I would like to save everything on the console to a text file at a certain time, but have not come across anything that does this. can anyone please help me in this area. Don't care what language it is in, my app is in C#.net.
Thanks
har04mich
|
|
|
|
|
If you want to redirect output to a file only that normally would have gone to the console, see Console.SetOut .
If you want to output to both console and file, you'll need to write a wrapper class that does both and use that.
If you want to capture the current contents of the console's screen buffer, you need to look at ReadConsoleOutputCharacter[^].
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Why my program is processing a file in 6 minutes and if I re-process same file it take 6 second.
|
|
|
|
|
Presumably on the first run none of the file was in cache. However, on the second run, the file was now cached, so reading the file was much faster as the data was already in memory, it didn't need to be read from disk.
When implementing file I/O, you should try to keep locality of reference: process a whole 'page' (4KB) at a time, rather than skipping all over the file. Every time you 'hit' a new page Windows has to read it from the disk into the cache. Windows does try to predict how you're going to use the file in future based on your previous accesses, and it does read ahead, but the fact remains that disks are slow - you should use files carefully. If you do need to jump all over a data structure you could consider reading the whole file sequentially into memory, but if it's a big file you could end up just swapping it straight out to disk again, if you don't have enough physical memory for the whole file.
If you were simply reading the file from beginning to end, some other process was probably using the disk heavily at the same time.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hi all,
I was wondering and have been looking for the following.
I created several executables in .NET which all have an assembly GUID in the assemblyinfo. From within one executable I want to start the other executables. I'm now using the path to start the executable, but I was wondering if it is possible to start an executable using it's GUID or finding the application path of the executable in the registry.
I don't think it's possible, because the GUID of an executable is not registered in the registry. But maybe someone else ever did it?
Don't ask why I want to do it like this and not using the path. I would just be cool using de GUID
Let me know if you have an idea.
Thanks,
Niels
|
|
|
|
|
not sure, but dont they use GUID as identifier for COM libraries (registry entries) - for non-COM assemblies, there's no registry entry in registry to search for. Your client would need to search the harddrive for an assembly with the right GUID? That doesn't make any sense.
Norman Fung
|
|
|
|
|
The idea I had behind it, is that at installation the executables GUID is registered in de registry and I would be able to find the path of the executable under the GUID (located in HKEY_CLASSES_ROOT\CLSID). So then I would always have a registered path to the files in de registry. But with the .NET deployment there no possibility to register a non-COM assembly.
Maybe I'm just shooting in space here?
|
|
|
|
|
I created a winform with some different panels,only one panel is visible at a time, I used the following code to implement it:
1. dont't add any panel into current form
2. void SwitchPanel(Panel panel)
{
//lastPanel recored current visible panel
this.Controls.Remove(lastPanel);
this.Controls.Add(panel);
lastPanel = panel;
}
when I switch between different panels, I just call SwitchPanel, it works well. However, if there are 2 panels panel1 & panel2, panel1 is the initial visible panel, panel2 has a button to display a modal dialog, when I switch to panel2 from panel1, and press the button, show the dialog, when the dialog closed, I got a "System.Runtime.InteropServices.SEHException: External component has thrown an exception: at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg).". Please help me on how to solve it, or to implement the switching model in another way.
Thanks a lot in advance!
Vinsent
------------------------------------
Make thing simple, but no simpler.
|
|
|
|
|
Are you using Application.EnableVisualStyles in your application?
We have a framework that uses TabbedMDIforms that threw the same exception in certain situations similar to your panel issues.
The solution for us was to ensure that Application.EnableVisualStyles was followed Immediatly by Application.DoEvents then the main form is constructed afterwards. If those lines appeared in any other order the Exceptions occured later on when switching the active Form.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
|
|
|
|
|
Thanks a lot for your help
I had spent a whole dull afternoon to solve it, and finally found the one statement fault, and I enabled visual style in another way by adding manifest xml.
Hopefully there comes a patch immediately
Vinsent
----------------------
Make things simple, but no simpler
|
|
|
|
|
Unfortunatly it doesn't look good for a patch. However I believe it is fixed in .Net 2.0, though I have yet to test it fully.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
|
|
|
|
|
Hello!
I got this error:
'0' is not a valid vaue for "value" . 'value' should be between 'minimum' and 'maximum'
when I try to minimize a form with a datagrid on it.
This is the code I have on my Resize function for my form:
dataGrid->TableStyles->Clear();
ctrlWidth = dataGrid->get_Width();
DataGridColumnStyle * colStyle1 = new DataGridTextBoxColumn();
colStyle1->MappingName = S"Internal Address";
colStyle1->HeaderText = S"Internal Address";
colStyle1->Width = ctrlWidth/2-2;
DataGridColumnStyle * colStyle2 = new DataGridTextBoxColumn();
colStyle2->MappingName = S"External Address";
colStyle2->HeaderText = S"External Address";
colStyle2->Width = ctrlWidth/2-2;
DataGridTableStyle * ts = new DataGridTableStyle();
ts->GridColumnStyles->Add(colStyle1);
ts->GridColumnStyles->Add(colStyle2);
ts->RowHeadersVisible = false;
this->dataGrid->TableStyles->Add(ts);
I could really use some help! thanks
|
|
|
|
|
hello,am a new user to C# sharp. when i use a datetimepicker ( format set to short), along with some more controls in a form, the first time i executed the project, Iam able to get the focus in the Datetimepicker control(by pressing tab).
But if u select a new value in the control and use tab again am not getting the focus in datetime control. IS THIS A PATCH IN DATETIME CONTROL?
But when u click on it , the mousedown event makes the selection. so, iam thinking of invoking the mousedown evnet in the Enter Event(when the control is active by pressing tab). But not sure how to do it. or is there any other way of achiveing this?
Please help me at the earliest. Much Thanks.
Regards,Manivannan.P
|
|
|
|
|
I've a quick question. I'm playing around with the ListView and am having trouble setting the BackgroundImage Property. Actually I can set the property without any trouble however the image is never displayed. I've successfully set this property (and seen the image) on a number of other controls but when it comes to the ListView this seems to be broken. Any ideas / has anyone else run into this? I'm very new to Windows.Forms so please excuse my ignorance if this problem is simply a result of this. (I've found a few message boards with people looking for help with this similar problem in the ListView control but no fixes yet)
Thanks in advance
-flip
|
|
|
|
|
hello,am a new user to C# sharp. when i use a datetimepicker ( format set to short), along with some more controls in a form, the first time i executed the project, Iam able to get the focus in the Datetimepicker control(by pressing tab).
But if u select a new value in the control and use tab again am not getting the focus in datetime control. IS THIS A PATCH IN DATETIME CONTROL?
But when u click on it , the mousedown event makes the selection. so, iam thinking of invoking the mousedown evnet in the Enter Event(when the control is active by pressing tab). But not sure how to do it. or is there any other way of achiveing this?
Please help me at the earliest. Much Thanks.
Regards,Manivannan.P
|
|
|
|
|