|
Actually, the abstract class our user control inherited is Windows.Forms.UserControl ( I say Windows.Forms.Control before, don't know if it makes any difference). When our new created usercontrol inherited this abstract class, you can not see it totally from design view.(The error shows the abstract class can not be loaded, etc. But we referenced this abstract class in the project, there is no compile error). Interestingly, when you remove inheritance, it can be shown in design view correctly.
Any idea?
|
|
|
|
|
This is a known "bug" with VS.NET; a couple solutions available but each require you to change the design.
First is to take all of the methods that would normally be left to be implemented and put it into an interface; then make the end usercontrol implement that.
Second is to provide dummy implementations that just throw a NotSupportedException or some other exception. Make sure to mark these methods as virtual
James
Simplicity Rules!
|
|
|
|
|
|
I have a problem with ReadCallback when I'm using sockets. Here's my problem: i'm writing an internet chat program. When user sends me a messages at large time intervals, everything is OK, but if he's flooding me, ReadCallback gets lots of calls. This causes that many Readcallback is calling and this causes overlapping messages in socket. Socket treats some messages as a one big message (they were sent as a separate messages). As a result of this the message is not easy readable... My ReadCallback begins with Monitor.Enter(RecQueue) and ends Monitor.Exit(RecQueue) [RecQueue = new Queue()]. How to force socket not to overlap multi messages into one?
Here is my ReadCallback code:
public void ReadCallback(IAsyncResult ar)
{
Monitor.Enter(RecQueue);
StateObject state = (StateObject) ar.AsyncState;
state.workSocket.Blocking = false;
Socket handler = state.workSocket;
handler.Blocking = false;
int read;
read = handler.EndReceive(ar);
if (read > 0) //display a message
{
DisplayMessageProcedure("the message");
}
else
{
//close the connection
handler.Close();
}
if (handler.Connected == true)
{
handler.BeginReceive(state.buffer,0,StateObject.BufferSize, 0,
new AsyncCallback(ReadCallback), state);
}
Monitor.Exit(RecQueue);
}
public class StateObject
{
public Socket workSocket = null;
public const int BufferSize = 1024;
public byte[] buffer = new byte[BufferSize];
public StringBuilder sb = new StringBuilder();
}
public void ListenProcedure()
{
IPAddress ipAd = IPAddress.Parse("0.0.0.0"); //all interfaces
IPEndPoint localEP = new IPEndPoint(ipAd, System.Convert.ToInt32(PortEdit.Text));
sock = new Socket(localEP.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
sock.Blocking = false;
sock.Bind(localEP);
sock.Listen(1);
sock.BeginAccept(new AsyncCallback(AcceptCallback), sock);
}
HELP!!!
|
|
|
|
|
Hi,
It seems as .NET uses double for all math calculations. I do not actually need the precision used by double and as such was thinking about using float. I guess .NET will cast all my values to doubles, which will mean a performance impact. Any suggestions?
Thanks,
Jurgen
|
|
|
|
|
Anonymous wrote:
It seems as .NET uses double for all math calculations
Do you mean in the Math class or C#?
In C# you can use floats in expressions and floats will be returned, just make sure you use the f (or F) suffix on literals when appropriate.
float size = 10.1f;
|
|
|
|
|
Hi all - I'm toying around with the events and I'm having some trouble.
I have a series of events I want to fire asynchronously, one after the other. That is, once one completes asynchronously, I want it to fire the next appropriate event.
I've been looking at the "bed time story" for events offered by Chris Sells (http://www.codeproject.com/csharp/delegate_bedtime.asp)
but I'm a bit confused.
Can someone explain these lines of code to me:
foreach( WorkCompleted wc in completed.GetInvocationList() ) {
wc.BeginInvoke(new AsyncCallback(WorkGraded), wc);
}
WorkCompleted is a delegate defined as: delegate int WorkCompleted();
completed is an event of type WorkCompleted
The rest I'm a bit confused about. I think that what's happening is that we're looping through each method that's been added to the event. We invoke each method on a seperate thread, and as soon as that thread is invoked, we call the "WorkGraded" method. What I'm not sure of is what thread WorkGraded is called on. Is it on the same thread as the method that has just been invoked? Or on the thread that called the method? Also, I don't understand the puprose of the second parameter in the BeginInvoke function. What does it do?
Thanks in advance.
- Sabran
|
|
|
|
|
Just to keep this simple...
I want to draw a circle in my about box that writes over all the text, bitmaps, etc.
So, I override OnPaint and do a ...
e.Graphics.DrawEllipse( Pens.Black, 0, 0, 500, 500 );
... but the circle is more of a background graphic and the text gets written over it. I've also overrode the OnPaint method to get the same results.
Sure I can set transparency on text, but I want this circle to overwrite anything in it's way... toolbars, status bars, etc.
Any thoughts??!
|
|
|
|
|
I am creating a very simple console application to read a portion of the registry into a class object called TrxRegistry under a TrxRegistry namespace. The registry access is working with no problems using hardcoded strings. I've now added a resource file called TrxRegistry.resx where I've associated the names of the registry values with descriptive names. The program compiles with no errors, but when I run it, I'm getting a resource exception.
I create a Resource Manager:
ResourceManager rm = new ResourceManager("TrxRegistry",this.GetType().Assembly);
and then access it by opening the registry key (which is defined in the resource file):
RegistryKey key = Registry.LocalMachine.OpenSubKey(rm.GetString("TRXKEY"));
I get this exception:
Could not find any resources appropriate for the specified culture (or the neutral Culture) in the given assembly. Make sure "TrxRegistry.resources" was correctly embedded or linked into assembly "TrxRegistry".
baseName: TrxRegistry locationInfo: <null> resource file name: TrxRegistry.resources assembly: TrxRegistry, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
The Build Action property for the TrxRegistry.resx resource file is set to Embedded Resource.
I didn't think I had to do anything for an embedded resource file. I thought you only had to use a command line assembly program for multiple language DLLs.
Does anyone have an idea what might be wrong?
Thanks in advance!
Derek
|
|
|
|
|
Instead of calling the constructor where you pass in the root namespace (which I think is telling it to look for culture specific resources) what happens if you call the constructor that gets its information from a type (ala Windows Forms) new ResourceManager(typeof(TrxRegistry));
Just a shot in the dark
James
Simplicity Rules!
|
|
|
|
|
I just tried your solution and it works! I figured out that I wasn't including the namespace when creating the Resource Manager:
Before:
ResourceManager rm = new ResourceManager("TrxRegistry",this.GetType().Assembly);
After:
ResourceManager rm = new ResourceManager("TrxRegistry.TrxRegistry",this.GetType().Assembly);
I like your code much better - no strings and less typing!
Thanks!
Derek
|
|
|
|
|
Cool
I think your method will need to be used if you want to use culture-specific resources; if you want .NET to automagically load them for you anyway.
James
Simplicity Rules!
|
|
|
|
|
How can I create form inside second ? I dont see anything such Create(HWND hParent)
In MFC e.g.:
CDialog dlg;
dlg.Create(IDC_DIALOG1,this);
dlg.ShowWindow();
I think programing using MFC or/and API is more logical than C#.
Wiizi
|
|
|
|
|
|
no, only create form inside second. e.g. you have treectrl and when you select item -> show form with setting ....
Wiizi
|
|
|
|
|
Will this work
In the event handler for the tree control
public /* some tree event handler*/
{
Form2 form2 = new form2();
form2.Show(); // or form2.ShowDialog() - for modeless
}
Form2 is the class you created for the second form? I might be missing something here so let me know.
|
|
|
|
|
ok...and how can i dock it into parent form ?
Wiizi
|
|
|
|
|
Ahh, so you want to dock it in the parent sort of like the netscape preferences dialog. If that's the case take a look at the following on CP
http://www.codeproject.com/cs/miscctrl/propertytree.asp
I think this is probably what your looking for. If not, let me know.
|
|
|
|
|
dlg.Parent = this;
or
this.Controls.Add(dlg);
James
Simplicity Rules!
|
|
|
|
|
I believe you will find that both of these solutions will throw an exception when the child is a Form derived object, or more specifically any top level control.
|
|
|
|
|
Yes ... it throw
Wiizi
|
|
|
|
|
See this post for the fix. If you don't want the user to be able to move the window, then set the FormBorderStyle to FormBorderStyle.None;
James
Simplicity Rules!
|
|
|
|
|
Oops, forgot you had to do this first
dlg.TopLevel = false;
James
Simplicity Rules!
|
|
|
|
|
I like...
|
|
|
|
|
I create a class now I want to access to my form from this class.So how can I access to the main form in C#?
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|