|
|
A long time ago i found a win32 function called HideCaret[^], you can try to import it. Then when the textbox has received focus (i think that is when it shows the caret, i'm not sure though...) you can call the HideCaret function with the handle of the textbox as the parameter.
Hope this helps!
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick || Fold With Us! || Pensieve || VG.Net ||
|
|
|
|
|
using System.Runtime.InteropServices;
...
[DllImport("user32.dll")]
public static extern bool HideCaret(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern bool ShowCaret(IntPtr hWnd);
public bool HideCaret()
{
return HideCaret(this.Handle);
}
public bool ShowCaret()
{
return ShowCaret(this.Handle);
} Note: As soon as any text is typed (at least in the RichTextBox), the caret is shown again automatically.
|
|
|
|
|
|
Does [DllImport("user32.dll")] mean that the user32.dll has to be present on the user's machine at runtime, or is it just embedding the code into the app during compilation?
|
|
|
|
|
Yes, user32.dll must be present at runtime. However, all Windows systems (that can run the .net framework) have this DLL, so it shouldn't be an issue.
|
|
|
|
|
Well okay, this won't be a problem then, thanks for the answer.
But then again, it disturbs the eye of the .net purist, as he would prefer not to use 32API code. And more, the HideCaret function does not hide the caret sufficiently. One might put the call into the MouseDown handler for the user can click on the TextBox without seeing the caret, but when he types anything, the caret is back again, as you mentioned earlier in this thread. So you need to manipulate the KeyPress handler as well, or maybe you better take the SelectionChanged handler for that. But still, when you maximize, resize or overlay your window, the caret will return once more, and this is more difficult to treat. You end up dealing with a bunch of events, and each time you'll find another bug bringing this damn caret back to view, like Herpes.
So I found another solution of the HideCaret-problem, and it is a quite simple one. The caret is present when the control has focus and never when it has not, no matter whether the HideSelection property is set to true or false. So all you have to do is to take away focus from the control. The command is
this.SelectNextControl(this, true, true, true, true);
For this you need at least a second control on the form, and that one must be visible and must have TabStop set true. If your form has several controls, there is no further problem. If the TextBox (or RichTextBox) is the only control on the form, then you need to add a "bogus" control, for the selection can cycle (by pressing Tab for example). Any control will do the job, might be a button, a label, or even another TextBox (wich you, as a bonus, can use for logging purposes or so). Set the "bogus" control (=control2) to Margin (all 0), Size (0, 0), TabStop (true), Visible (true). Your primary TextBox (=textBox1) you set to TabStop (false), Cursor (Default), Visible (true). Check TabIndex to be different in both controls.
Now, you handle the MouseDown event of the TextBox (here it's a RichTextBox):
private void richTextBox1_MouseDown(object sender, MouseEventArgs e)
{
this.SelectNextControl(this, true, true, true, true);
}
You must also handle the MouseUp event, because otherwise clicking the right mouse button will bring the caret back. (I don't know why this behaviour occurs, it seems that the right mouse button takes effect only when releasing, in opposite to the left button.)
private void richTextBox1_MouseUp(object sender, MouseEventArgs e)
{
this.SelectNextControl(this, true, true, true, true);
}
Instead of the both Mouse events, you may use the Enter event (it's more simple):
private void richTextBox1_Enter(object sender, EventArgs e)
{
this.SelectNextControl(this, true, true, true, true);
}
With this you are done. The TextBox will never get focus anymore, while window functionality like scrolling, resizing etc. still work. In most cases when you want to make disappear the caret, you don't need to write to the TextBox, but only show some (formatted) text, like an info-sheet or so. If you want to write to the TextBox for any reason, you may add a KeyPress handler to your second control:
private void control2_KeyPress(object sender, KeyPressEventArgs e)
{
richTextBox1.Select(richTextBox1.SelectionStart, 0);
richTextBox1.SelectedText = e.KeyChar.ToString();
}
This is quite easy, and if control2 is another textbox, it could perfectly serve as a key logger or something similar.
Well, this posting got a bit long now. Anyway, I hope it will help some guys (and girls) out there, messing around with a never disappearing caret like I did... I think I will write an article even, about a RichText based Help feature, with this as a part of it.
See you.
Kuno
-- modified at 10:26 Monday 13th March, 2006
|
|
|
|
|
Hi,
I would like to write a little program which monitors a specified Service, and if it isn't running, starts it? how is this possible please?
Thanks
|
|
|
|
|
Hi!
Look up the documentation for the ServiceController class (namespace System.Serviceprocess ).
Regards,
mav
|
|
|
|
|
|
Hello to all,
In my project i hae to generate a stream in form of UDP Packet & this packets are captured by windows media player. But i don't know how to detect & play.I do same thing with TCP & I am success.
If any one have idea about UDP tell me.
Thank you
Divyang Mithaiwala
|
|
|
|
|
hi . .
How to open a .pdf file in Dotnet with C# as Code behind
by Clicking a button a pdf file should open
Help me its urgent
Regards
Venkatram.s
|
|
|
|
|
In what way do you want to open it? You can open the file as a binary file if you want to read the contents. If you want it to open in Adobe Reader on the client computer, it's not a task for code behind. Just link to the file and let the browser handle it. You might also want to supply a link to the download page at Adobe, for users who don't have the reader installed.
---
b { font-weight: normal; }
|
|
|
|
|
im in Windows application .
when a button is clicked a .pdf file shoul open in Adobe Reader . .
help me
Urgent
Venkatram
|
|
|
|
|
Hi VenkataRaman,
As a simple solution you can use Microsoft Web Browser control to display the file.
axWebBrowser1.Navigate(@"C:\FIGHCatalogue.pdf");
Thanks and Regards
Pani.
|
|
|
|
|
System.Diagnostics.Process.Start(string fileName); should solve your problem,
if you want to show the .pdf file in an extern Adobe Reader window.
Arne
-- modified at 6:49 Friday 27th January, 2006
|
|
|
|
|
I want to show window that it's like open.showmodelessdialog in web application. The second window always on the first window. besides, the first window can be operateed.
|
|
|
|
|
Secondwindow.AlwaysOnTop = true?
|
|
|
|
|
If I set SecondWindow.TopMost as True, then show other problem that the first window bring to back, the second window still on top.
|
|
|
|
|
You may recall I asked about binary serialization earlier. I did it but (after a suggestion from someones' reply) I wanted to try something I never tried before so I want to get my feet wet in XML. As you may recall, I have 2 classes of lists derived from collections (class ArrayList to be specific) with objects in the list (also derived from System.Object). I can serialize both of them into one file but in the file I get:
<MyArray1 count="6">
...
</MyArray1><?xml version="1.0" encoding="utf-8"?>
<MyArray2 count="2">
...
</MyArray2>
That "?xml" tag, which as I understand is the document start tag that states it's XML, what version of XML it is and what encoding it has, should only be at the top and not in the middle.
Here's the core of the XML code:
StreamWriter writer = new StreamWriter(dlg.FileName);<br />
<br />
XmlSerializer ser1 = new XmlSerializer(typeof(Array1));<br />
ser1.Serialize(writer, array1);<br />
<br />
XmlSerializer ser2 = new XmlSerializer(typeof(Array2));<br />
ser.Serialize(writer, array2);<br />
<br />
writer.Close();
I figure it's doing that because the second XML serializer figures it's the only XML serializer so it writes that document start tag which I want to get out of there. I found an overloaded constructor for the XmlSerializer which is (Type, Type[]). I figure that's what I'm looking for because the second argument takes "extra types". I tried creating a Type array with a single element (the typeof(Array2)) and the first argument keeps typeof(Array1) but in runtime, I get an exception that says "Specified cast is not valid" at Write1_Array1. Some web pages say it's because it's trying to cast my derived class as the base class and it doesn't like that but I don't know if they are having the same issue. I don't quite know how to fix this, can anyone help me?
|
|
|
|
|
|
Okay, I understand. However, could I create an instance of XmlRootAttribute, and potentially set some namespaces also instead of using a dummy class?
|
|
|
|
|
Has a Excel file like that:
Title
Field1 Field2 Filed3
1 AA 1.1
2
3a CC 3.3
4 DD 4.4
I wrote a program in order to import the excel file datas to DataGrid:
OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Test.xls; Extended Properties=Excel 8.0");<br />
connection.Open();<br />
DataTable dt = new DataTable("Orders");<br />
OleDbDataAdapter da = new OleDbDataAdapter();<br />
da.SelectCommand = command;<br />
da.Fill(dt);<br />
this.dataGridTest.DataSource = dt;
Why in the DataGrid show as:
F1 Title F2 ------> This is header
(null) Field2 Filed3
1 AA 1.1
2 (null) (null)
(null) CC 3.3 ------> Note this line column 1 is null!
4 DD 4.4
If the Excel file like this:
Title
Field1 Field2 Filed3
1 AA 1.1
2a
3a CC 3.3
4a DD 4.4
That the DataGrid turns to like this:
F1 Title F2 ------> This is header
Field1 Field2 Filed3 ------> Note the Field1 now is not null
(null) AA 1.1 ------> Note this line column 1 is null!
2a (null) (null)
3a CC 3.3
4a DD 4.4
Why? How can i prevent this result? (I had try to make the column 1 is Text format not Generic, but also yet)
=== Game is power! ===
|
|
|
|
|
Hi Libra,
Can you try something with your command object.
Insted of selecting a sheet can you try selecting a range of cells.
command.CommandText = "Select * from [Sheet1$A2:B7]";
Thanks and Regards
Pani.
|
|
|
|
|
Thx for you help.
I try as your said but it's trashy. Select of a part datas is base on the Select of whole sheet.
I wonder if the OleDb Engineer adjust the type of each excel column when transfer, so when the column looks has more numerical value that it make the numerical type, when the column looks has more string value that it make the string type.
=== Game is power! ===
|
|
|
|
|