|
You might want to give specifics on how you're storing it (separate file, embedded resource in an assembly, etc.) and how you're loading it. It's kind of hard to diagnose a problem with specifics (it's like telling a doctor you have a pain without saying anything else).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
leppie wrote:
As I read today, the Cursor class only supports black and white cursors.
If it is the case that the Cursor class only supports black and white cursors, it changes the nature of my question from 'what am I doing wrong' to 'how can I display coloured cursors'. As Heath Stewart quite justly comments, let me show me what I've done sofar to create, load and display my cursor.
I created the cursor with Visual Studio 6.0. (By the way, earlier I created one by selecting "Cursor file" from the "Add New Item" dialog in Visual Studio .Net 2003 but that file appears to be an icon instead of a cursor. In the Properties Window it says "Icon Editor" and the hotspot tool is disabled. My old Visual Studio 6.0 recognised the file as an icon, too. I guess this may be a bug in Visual Studio .Net 2003 and I probably need an update for it. This is a different matter, however.) Anyway, this 16-coloured cursor works fine in a C++ 6.0 project. I also tested one of the coloured cursors that comes with WindowsXP; it also is displayed in monochrome, so I think we can discard the cursor file itself as the problem.
I embedded the cursor by setting the Build Action to Embedded Resource. I declare the cursor:
private Cursor MyCursor;
and in the constructor of my user control I load it:
System.Reflection.Assembly ThisDll = System.Reflection.Assembly.GetExecutingAssembly();<br />
System.IO.Stream TheRes;<br />
TheRes = ThisDll.GetManifestResourceStream("MyNamespace.MyCursor.cur");<br />
MyCursor = new Cursor(TheRes);
(I tried using simply
MyCursor = new Cursor(this.GetType(), "MyCursor.cur"); or
MyCursor = new Cursor(this.GetType(), "MyNamespace.MyCursor.cur");
but that didn't work: the dataStream remains empty, apparently.)
I asign the cursor (in special cases) to the user control by:
this.Cursor = MyCursor;
All in all, I'm doing nothing odd, I would say. So where have my wonderful colours gone?
I would appreciate anyone's help on this. I cannot believe C# only allows monochrome cursors.
Thanks.
|
|
|
|
|
i want use from Axmediaplayer and i want doubleclick on it and then open another form .
i want serialize and deserialize AxmediaPlayer .
please help me
thanks.
|
|
|
|
|
You can serialize its properties, but not the whole player. Instead of serializing it to pass it to another form, just add it to the other Form 's Controls collection. So long as the forms are on the same thread, the AxMediaPlayer control will remove itself from it's current Parent 's Controls collection. This also re-creates the handle, though, which also makes the video stop.
If you're trying to implement a small <-> large switching, the media player itself already supports this. Download and install the Windows Media SDK (very small) from MSDN[^]. Then take a look at the scripting object model in the HTML Help file, specifically the PlayerApplication.switchToControl and PlayerApplication.switchToPlayerApplication methods. The scripting (i.e., automation) object model is the same as what is created for the interop assembly you're using.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
HI,
In my system, MyNetworkPlaces-> I have few network folders .
when I click those to view, it prompts the dialogbox to connect to that folder. If I give username and passwork it connects.
so now in my C# application, I am asking user to select a folder, by showing Browse for folder dialog box with server machine shared folder as default folder. The thing is before showing the file dialog box, I want to know whether it is connected to the server or not, if not I need to prompt the dialogbox with username and password fileds for connecting to it. so How can I achieve this using C#? and what class I need to use for connecting to network folder? I am really struggling for this. Please help me as soon as possible.
For ex:
I want to connect to \\machine1\somefolder
or \\machine2\somefolder, I need to know whether is it accessinble for user machine, if no i need to prompt the dialog box to connect with username and password as windows shows.
Thanking you
Regards
Subin
|
|
|
|
|
As has been covered in this forum several time before, this is a feature of Windows, not of networking itself (which expects a connection with the appropriate credentials). If the user can't access the folder, you should get a SecurityException . In such an event, you simply open a dialog (which you must create) to prompt for a username and password. You use that information - and do not store it - to impersonate the user using WindowsIdentity.Impersonate (for which the documentation contains an example of how to use it). Create a WindowsPrincipal using that identity, set that as the thread princial (assign it to the Thread.CurrentPrincipal property) and re-attempt the connection.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Good day,
I have a dll that disables/enables the keyboard using the SetWindowsHookEx, CallNextHookEx and UnhookWindowsHookEx api's. Now when i run my application, at first it does its job, but after awhile it generates this error:
/*
An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll
Additional information: Object reference not set to an instance of an object.
*/
The error points to this part of my code:
static void Main()
{
try
{
Application.Run(new Form1());
}
catch(Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message); <----- error
}
}
Does this have to do with garbage collection?
Thanks Arthur
|
|
|
|
|
That doesn't tell us much. All it says is that somewhere in the Application.Run() method a NullReferenceException occurs.
You will need to find out where the exception was thrown from. For debugging purposes temporarily remove the try/catch statments so that the exception gets thrown out and allow the debugger to handle it. From there you should see lots of other useful information - The debugger will jump the source to the relevant line (or sometimes the line after), if it happened inside some system code you don't have access to the call stack will show you where that is.
If this information is not enough to work out the problem, please, at least post the call stack.
Arthur01291981 wrote:
Does this have to do with garbage collection?
What makes you think that? You know more about your application than we do. Is their something you've not told us that you think might be relevant.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
To add to what Colin said (since a NullReferenceException is the most common exception - and the easiest to prevent!), putting a try-catch around Application.Run doesn't help unless an exception causes the main UI thread to abort, and most won't; it is in your case, which means it's occuring in the message pump, or application thread queue.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a problem with the richtextbox. I'd like to read a logfile, then reverse it. This did not seem to be possible with LoadFile so I read the file into an arraylist and outputs it to the richtextbox with AppendText. With this solution it will also be quite easy to add output filters.
The problem is that there seems to be problems with number of lines the richtextbox can hold. If I output 2000 lines it takes approx. 5s before it's done, 10000 lines I waited about 1 minute and it was still not finished. The logfiles will contain much more than 10000 lines so this is a big problem. Using LoadFile it takes no time at all. So something's very wrong with my solution, anyone that can hint to me what's wrong, and maybe suggest a better approach to this.
Since all files starts with the date I added a check that they e´start with 2004 otherwise I had >18000 lines in a logfile with 15000 lines. This seems to be me as one possible problem is that the logfile contains some "forbidden" characters that richtextbox cannot handle. Still LoadFile loads the file without problems.
private void button1_Click(object sender, System.EventArgs e)
{
StreamReader sr = new StreamReader("c:\\logfile.txt");
//StreamReader sr = File.OpenText("c:\\logfile.txt");
string input = null;
//Should read from the bottom, doesn't seem to work with LoadFile...
//richTextBox1.LoadFile("c:\\logfile.txt",RichTextBoxStreamType.PlainText);
ArrayList myList = new ArrayList();
int linecnt = 0;
while ((input = sr.ReadLine()) != null)
{
if ( input.StartsWith("2"))
{
myList.Add(input);
//linecnt++;
}
}
sr.Close();
myList.TrimToSize();
myList.Reverse();
richTextBox1.Clear();
richTextBox1.Enabled = false;
int q = myList.Count;
//richTextBox1.Text = myList.Count.ToString() + "\t" + linecnt.ToString() + "\n";
for (int i=0;i < myList.Count ;i++)
{
richTextBox1.AppendText(myList[i].ToString() + "\n");
}
richTextBox1.Update();
richTextBox1.Enabled = true;
}
|
|
|
|
|
Looking into it more it's seems to me that it works as intened but as soon as the loop where the text is appended to the richtextbox exceeds 2-3000 it will take several minutes.
Is there any better way to add text to the control than AppendText? I'd like to stick with richtextbox since I'm thinking of highlighting some lines.
|
|
|
|
|
The problem lies with how your building the string that is in the RichTextBox. Since Strings are immutable in the .NET Framework, every time you use .AppendText you're actually making a copy of the string in the .Text property, and appending the .AppendText string to it, and then killing off the old string and setting the .Text property to the new one. Do this 3,000 times and the GC has to go back and clean up ALOT of orphaned String objects. This probelm will continue to get worse and worse until the GC catches up to what your doing. Also, the RTB will repaint itself every time the .Text property changes.
The work around for this is to use a StringBuilder object to build the complete string BEFORE you send it to the RichTextBox. You can use the .Capacity property, or the .EnsureCapacity method to setup the StringBuilder with the size of the log file before you start appending text to it. This way, you'll once again avoid excessive allocations as your adding your lines to it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Using stringbuilder did the trick. Thanx a lot.
|
|
|
|
|
here are a few possible adjustments you can make to your code.
string reader stuff blah blah blah
while ((input=sr.RealLine()) != null)
{
if (input.StartsWith("2"))
{
myList.Add(input);
}
}
sr.Close();
richTextBox1.Clear();
System.Text.StringBuilder data = new StringBuilder(myList.Count*avgLen);
for (int i=myList.Count; i>=0; i--)
{
msg.Append(myList[i]);
msg.Append(System.Environment.NewLine);
}
richTextBox1.Text = msg.ToString();
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
It's so strange that today when I compile some sample code on .net remoting, vs.net 2003 says System.Runtime.Remoting.Channels.Tcp does not exist! also,the .Http namespace does not exist.
I remembered I should have comiled and ran some examples contained Tcp or Http namespace.
Framework 1.1.4322, Win2K advanced server with sp4.
And I reinstalled VS .net 2003 but I takes no effect.
What's the problem? Any one had encountered?
Thanks.
|
|
|
|
|
|
fine. It was that very reason.
thanks.
fay
|
|
|
|
|
Hi,
I'd like to know how can I overload the '=' operator?
the standard '=' does not do what I want...
Best regards.
thanks.
There is no spoon.
|
|
|
|
|
an example
using System;
class Player
{
public int neili;
public int tili;
public int jingyan;
public int neili_r;
public int tili_r;
public Player()
{
neili = 10;
tili = 50;
jingyan = 0;
neili_r = 50;
tili_r = 50;
}
//
public static Player operator ++(Player p)
{
p.neili = p.neili + 50;
p.tili = p.tili + 50;
p.neili_r = p.neili;
p.tili_r = p.tili;
return p;
}
//
public static Player operator +(Player p1, Player p2)
{
Player p = new Player();
p.neili = p1.neili +p2.neili;
p.tili = p1.tili + p2.tili;
p.neili_r = p.neili;
p.tili_r = p.tili;
return p;
}
public static void Main()
{
Player p1 = new Player();
Player p2 = new Player();
p1++;
Console.WriteLine(" {0}", p1.neili);
Player p = p1 + p2;
Console.WriteLine(" {0}", p.neili);
}
}
fay
|
|
|
|
|
hi,
I need to overload the assignment operator (=) not the + or ++.
I want to replace this:
<br />
for (i=1; i < m_nHeight; i++)<br />
for (j=0; j < m_nWidth; j++)<br />
{<br />
m_board[i-1, j].IsSet=m_board[i, j].IsSet;<br />
m_board[i-1, j].BrushType=m_board[i, j].BrushType;<br />
m_board[i-1, j].ForegroundColor=m_board[i, j].ForegroundColor;<br />
m_board[i-1, j].BackgroundColor=m_board[i, j].BackgroundColor;<br />
m_board[i-1, j].LinearGradientMode=m_board[i, j].LinearGradientMode;<br />
m_board[i-1, j].HatchStyle=m_board[i, j].HatchStyle;<br />
};<br />
by simply this:
<br />
for (i=1; i < m_nHeight; i++)<br />
for (j=0; j < m_nWidth; j++)<br />
m_board[i-1, j]=m_board[i, j];<br />
when I use the standard '=' operator the standard assignment fails. that's why I would like to rewrite this operator.
There is no spoon.
|
|
|
|
|
You can't overload the '=' operator. You can overload these[^] operators.
As a workaround, you could write an Assign, or CopyObject, whatever you want to call it, method into your class that accomplishes the same thing.
for (i=0; i < m_nHeight; i++)
for (j=0; j < m_nWidth; j++)
m_board[i-1, j].Assign(m_board[i, j]);
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I was thinking abuot it, but it's not the way I want
I guess C# allows to overload '='...
There is no spoon.
|
|
|
|
|
bouli wrote:
I guess C# allows to overload '='
As the topic that Dave linked stated - straight from the MSDN documentation - the = operator cannot be overloaded whether you like it or not.
You can, however, implement a cast operator so that if you want to customize assignment from another type (say an int to your struct), you could actually do something like this:
MyStruct s = (MyStruct)1;
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Heath!
ok, thanks,
the code will remain like that...
by the way delegates are very convinient :P I can combine them with DirectX
There is no spoon.
|
|
|
|
|