|
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsApplication11 {
public class FormA : Form {
public virtual new Size PreferredSize {
get {
return new Size(300, 300);
}
}
}
static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form form = new FormA();
form.Size = form.PreferredSize;
Application.Run(form);
}
}
}
Chris
|
|
|
|
|
chris175 wrote: public virtual new Size PreferredSize { get { return new Size(300, 300); } }
What is "Size" ?
|
|
|
|
|
|
Its Working Fine
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsApplication11
{
public class FormA : Form
{
public virtual new Size PreferredSize
{
get
{
return new Size(300, 300);
}
}
}
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form form = new FormA();
Application.Run(form);
form.Size = form.PreferredSize;
}
}
}
|
|
|
|
|
I encountered something similar, and got the right size AFTER the call to Application.Run (). If you get the size in FormA's Load method, it might be right at that point.
|
|
|
|
|
Because when you Application.Run(form) , InitializeComponent() gets called which probably resets the size of the form.
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
The wrong size is placed on the form BEFORE Application.Run(form) is called. I dont think it has anything to do with InitializeComponent() function since there isn't one within the class FormA .
Chris
|
|
|
|
|
carbon_golem wrote: Because when you Application.Run(form), InitializeComponent()
No, you have it all wrong, there is no magic involved. InitializeComponent() is usually called from the Form's constructor.
|
|
|
|
|
If you do FormA form = new FormA() then your method will be called, otherwise the System.Windows.Forms.Control.PreferredSize property will be called (can be seen in .NET reflector). I guess this has to do with the fact that PrefferedSize in Control is not marked virtual or abstract .
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
PreferredSize isn't virtual; you cannot override it.
Instead your code created a new virtual property with the same name - but your Main method refers to the original PreferredSize property.
You should override the virtual GetPreferredSize method instead.
|
|
|
|
|
That is what I was looking for... Thanks
|
|
|
|
|
Hi everybody.
I have a class that uses a socket to comunicate with remote server. In that class I have two threads - one for sending data and one for receiving. I am not shure if I have to lock the socket instance becouse I use it in both threads. The problem is if I lock it when receiving the object is locked all the time becouse socket.receive blocks until it receives some data. My simplified receiving methods is
void read()
{
byte[] buffer = new byte[ReadBufferSize];
int readCount;
while (true)
{
readCount = 0;
try
{
//lock(_socket)
//{
readCount = _socket.Receive(buffer); // this call blocks
//}
}
catch (Exception ex)
{
}
if (readCount > 0)
{
//Notify the main thread that data was received
}
}
}
Does anybody has any solution? Maybe I should use some other method(not socket.receive)? Is locking the socket instance even necessary? Any advice will be apreciated.
Uros
|
|
|
|
|
From my experience, you should not have to lock the socket.
|
|
|
|
|
Thanks. Are you shure about that? I mean do you know that, or you didn't use locking and had no problems becouse of it?
Uros
|
|
|
|
|
Nope, AFAIK NetworkStream is bidirectional, so you can send and receive at the same time. Try it without locks. If it breaks, investigate, find a solution and write an article to tell us about it
|
|
|
|
|
Where can i post a thread for help with javascript?
There is no "JS" forum?
Thanks
|
|
|
|
|
|
you can also post it in web development section.
if this releated with asp.net , you can alos post over asp.net fourm
Thanks
|
|
|
|
|
How can in WebForm1 the function in WebForm2?
i try WebForm2. and look up for other overloads, but i get view the function.
Any one can help. A big thanks!
|
|
|
|
|
ewin,
You might get more help asking this in the ASP.NET forum.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
I am not shure I understand the question corretly. But in asp.net pages, a Form is loaded(Form1 in your example), when user requests this page. So there will be no instance of Form2. If you have to call methods from Form2 I think you will have to use static methods
I hope this helps!
|
|
|
|
|
doesnt sound like the best idea, you can however put the functions in a new util class in the same namespace or namespace.Util and inlcude that in your using statements(if you use the .util one) and access that functions that way, it makes life easier 6 months down the road when you have to change a method in form 2 you wont have to worry about where else it might be called at, but you know the util class would be used in other places so debuging may be easier for you. and if for some reason you change what form 2 does or replace your function and delete it, you wont accidently break another form you werent changing, this happened to a dev we had working here a few times then he finally took my advice after he couldnt figure out what was going on, now the code behind pages are clearer, and it forced him to start thinking about how to do things generically instead of copying the same function to 15 different files... hope it helps.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
ewin wrote: How can in WebForm1 the function in WebForm2?
This is not the asp.net forum , please put it over ther.
Try to create separete class for accessing same function
|
|
|
|
|
Is it possible to expand a particular category and collapse another particular category in property Grid ? How can we do it.
Also if I do not have category , MISC is shown as category . Is it possible to remove "Misc"
Thanks ,
Rajan
|
|
|
|
|