|
HI,
I need to have a non-breakable hyphen in Word Doc.Only way can do this, sending " CTRL + SHIFT + -" to the word document. How can i type this(send this)to the Word using c#? Or is there any other method?
Kanch
|
|
|
|
|
Assuming the Word document has focus, you can use the System.Windows.Forms.SendKeys class to send keystrokes to the application.
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
As James T Johnson said, you can use SendKeys. But you can also find out the character code of a non-breaking hyphen, and use Word Automation to insert it.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I found the uni-code for the non-breaking hyphen(2011). Having a hard time using it.
Since i have to string-catinate this command to another string, i can not use sendkey command, i guess.. I am not sure
Any suggestions, sample code would be a great help.
thanks...
Kanch
|
|
|
|
|
I created a DataGrid and DataTable in code. I set the DataSource of the DataGrid to be the DataTable.
How do I set the alignment of the displayed cell data?
I messed around with the DataGridColumnStyle.Alignment Property but that seemss to only adjust the alignment of the column header. I need to right align the entire column of numbers.
|
|
|
|
|
I use DataGridColumnStyle.Alignment and it works. May be You have extra spaces on right in Your numbers?
Hi,
AW
|
|
|
|
|
Hi
How can i find the position of each of the spaces in this string?
String duh = "Its a beautiful day in the neighborhood";<br />
int c = 0;<br />
char[] s = duh.ToCharArray();<br />
for(int i = 0; i < s.Length; i++)<br />
{<br />
if(s[i].ToString() == " ")<br />
{<br />
c++;<br />
Console.WriteLine(c);<br />
}<br />
}
This code finds the 6 spaces in the string, but i'm having a hard time getting the IndexOf location of each of these spaces.
Any help would be appreciated.
|
|
|
|
|
How about
string s = "It's a beautiful day in the neighborhood";
for (int index = 0; index < length(s); index++) {<br />
if (s[index] == ' ') {<br />
Console.WriteLine(index);<br />
}<br />
}
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
Welcome to CP Julian! Always good to have more Microsofties around.
Hawaian shirts and shorts work too in Summer.
People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage...
-Anna-Jayne Metcalfe on Paintballing
|
|
|
|
|
Thanks for your help on this. it worked as you said, except it's actually
index < s.Length;
also, i was using " " instead of ' ' as you did and i was getting a compilation error. i didn't think it mattered, but i was wrong.
Thanks again.
|
|
|
|
|
I should've added my usual clause:
(Code was written on the fly, probably won't compile.)
The difference between " " and ' ' is that the first is a string of length one, and the second is a single character. So you can't compare a character such as someString[i] to " " (they're two different types)
if (someString[i] == " ") { // won't compile
// blah
}
...but you can to ' ' (since they're both of type char)
if (someString[i] == ' ') { // will compile and do what you think
// blah
}
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
My cheap $0.02:
Option #1:
the same code you have up there, but put the value of i (when s[i] is equal to " ") in a collection (Hashtable, ArrayList, what have you).
Option #2:
use IndexOf(" ") and cut the starting part of the string every time...
string s1 = "Its a beautiful day to be coding";
string s2 = s1; //To save the original s1 if needed
Hashtable ht = new Hashtable(); //Use whatever you need instead of an hashtable
while(s2.Length>0)
{
int k = s2.IndexOf(" ");
if(k<0)
{
break; //No more spaces found
}//IF
ht.Add(ht.Count, k); //Save in ht the index where the next space is found
s2 = s2.Substr(k+1); //Cut away everything up to the space
}//WEND
//Disclaimer: I have not compiled nor tested this code
Maybe it could be better to use a StringBuilder
HTH,
Olorin
|
|
|
|
|
this works fairly well, I subtracted 1 from the for loop
because it prints out 33 for what would be the next space.
This is the output.
4
6
16
20
23
26
<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
string str = "Its a beautiful day to be coding";<br />
string[] strs = str.Split( new char[]{' '} );<br />
int j = 0;<br />
int k = 0;<br />
for ( int i = 0; i < strs.Length - 1; i++ )<br />
{<br />
k = strs[i].Length + 1;<br />
Debug.WriteLine( k + j );<br />
j += strs[i].Length + 1;<br />
}<br />
}<br />
Bo Hunter
|
|
|
|
|
Hi
I'm new to C#. I heard that the .NET runtimes are platfrom independent and applications written in C# can be run on Windows, Linux, etc. But I just read on the mono site that Windows.Forms will be available in future versions of the Linux compiler by emulating them through Wine(ex). So what's the point now? When Windows.Forms will be emulated by Wine, why do I need C# then? Right now Wine can also run C++-Applications that make use of MFC, so what's the point of C#?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Well, that just doesn't make any sense. Right now Windows can run C++ applications written with MFC too but C# still has its place in Windows.
Same with Linux and Wine.
|
|
|
|
|
In the future I bet there will be full support for the .net framework on *nix, but someone will have to do it. I doubt MS will do the work.
|
|
|
|
|
Greg S. wrote:
So what's the point now? When Windows.Forms will be emulated by Wine, why do I need C# then? Right now Wine can also run C++-Applications that make use of MFC, so what's the point of C#?
Because MFC is not the only tool in the world and Windows.Forms may be about 5% of the .NET Framework.
Acting as a substitute for God, he becomes a dispenser of justice. - Alexandre Dumas
|
|
|
|
|
Maybe it's only about 5% of the .NET Framework, but unfortunately a very essential one if you want to write GUI applications
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I haven't found a clean way to remove a control (say a button) and any associated event handlers. What I do now is delete the control from the form, then find the event handlers in the code, and delete them. When I recompile, I get errors due to the deleted event handler code, and have to perform more surgery to clean them up. I'm new to dotNet, so be kind...
There must be an easier way!
|
|
|
|
|
If you're talking at design time,
then I have run into the same "problem"...
removing a control from the design view removes the declaration and instanciation of that control from the IDE-generated code but not anything related like the even handlers..
..I usually do that by hand.
If you're talking at run time, I think that removing the control from the Controls collection of the form should do the trick (the handlers are still in the compiled code but they will not get called...)
HTH,
Olorin
|
|
|
|
|
Sorry, I was referencing design time. The functionality you reference is what I have seen. It just seems odd that you can't delete the event handlers in one fell swoop.
Oh well.
Thanks for your reply.
|
|
|
|
|
Any handlers added by using the IDE will get removed when you delete the control. If you add handlers by hand then you'll have to remove them by hand as well.
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
What I see is the declaration and instantiation of a control (say a button) is removed when you delete the button, but not any associated event handlers, not even those created with the IDE.
|
|
|
|
|
You can also create a macro to do that for you
|
|
|
|
|
I need to pass a reference to my object
CEmployee
...
CallMyMethod(ref this);
but that doesnt work becuase this is read only.
how would a gain a writable reference to it?
nick
|
|
|
|