|
Just another possible solution:
private byte[] GetByteArray(string binaryText)
{
char[] c = binaryText.ToCharArray();
binaryText = new string(Array.Reverse(c));
BitArray ba = new BitArray(binaryText.Length);
for (int i = 0; i < binaryText.Length; i++)
ba[i] = binaryText[i] == '0' ? false : true;
byte[] result = new byte[binaryText.Length / 8];
ba.CopyTo(result, 0);
Array.Reverse(result);
return result;
}
|
|
|
|
|
Thanks a million. They both worked. I find that depending on what I am doing sometimes I dont have to reverse the bits. Anyhow this was a big help as I was stuck.
Thanks again
SAG, CANADA
|
|
|
|
|
I have a main form, call it A, which spawns another form B. When B spawns I want it brought to the front (easy), but if another program gets the focus, then the user switches back to A, I want B to be brought to the top if it was focused when the user switched to another program. Any easy way to do this? I have tried using the Enter/Leave/Activated/Deactivated events but it doesn't seem to work the way I think it should. If anything is unclear let me know. Thanks.
|
|
|
|
|
can't you just use ShowDialog? that should make B be active even if you select A.
Rob
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|
|
Rob Tomson wrote:
can't you just use ShowDialog?
I need to have access to A while B is open, otherwise I would.
|
|
|
|
|
Its a tricky problem because u dont want the form snapping back to B when ur only activating A and not an external app.
Still, i think u can do it this way (havent tried it but it looks pretty sound):
Create a timer in the B Form with a low interval. 1-10 miliseconds will do.
When B looses focus (deactivates), start timer and in the Tick handler check for the static member Form.ActiveForm and stop ur timer. If ActiveForm is FormA then dont do anything. If ActiveForm gives u Null then the active window is no longer part of ur app and u should set a property in ur A Form, for example SnapBackToB to true.
Whenever A handles and Activate event, check for _snapBackToB and if true, activate Form B.
That should do it.
Oh, one other thing, when Form B activates, it should always check for SnapBackToB in form A and set it to False.
GL, and if things dont work at all as I/u expect please let me know :p
P.D. Its important u stop the timer after first tick because, even if it doesnt harm the algorithm, a timer running with that small interval may not let windows detect correctly ur idle app and u might have issues with power management, screensavers, etc.
|
|
|
|
|
Could you elaborate on the ActiveForm static member? Should this be in A or B, and how/where should it be set/unset? Or are you referring to ActiveControl? Thanks.
|
|
|
|
|
U dont set Form.ActiveForm to anything. Its a read only property so u can't set it anyways. U read its value to know which form in ur application is the Operating System's active window. If the value u read is Null that means the active window is an external window to ur application or it could be that there really is no active window.
System.Windows.Forms.Form.ActiveForm[^]
When ur timer in Form B (which has started when Form B has been deactivated) triggers the Tick event for the first time, the event Handler which u should include in Form B should check for the static memeber Form.ActiveForm as I posted before.
After that its just a question of style. U can either make a public get/set property in either FormA (SnapBackToB) or in FormB (SnapBackToMe) or whatever. In the first case, when A activates it would: 1) Check if Form B is open 2)check its own property and if true it would give focus to Form B. On the other hand if property was in FormB, FormA would check when it activates: 1) If Form B is open 2) If FormB's SnapBackToMe is true, it would give focus to B. As I said before, this is a question of style and there are many many ways to implement this.
Of course there r some details i havent touched like handling correctly what happens when Form B is closed and not only loosing focus (remember that the Deactivate event triggers when closing a form too) and u dont want ur SnapBackToX property to remain true when ur form B is closing....but u should be able to sort that out without too many problems.
|
|
|
|
|
Haha, for some reason when you said "static variable" I didn't put 2 and 2 together and was looking for an instance variable, which is why I couldn't find it. Thanks for the reply, I'll go about implmenting it today and I'll let you know it turns out.
|
|
|
|
|
Thanks for the code. It all works ALMOST the exact way I wanted it to. For some reason if I tried to save the last active window (IE on return to the app, either make the main window the active one or the message window the active one depending on which was activated last) it would go back and forth between the two and then settle on the main window. So instead I just brought the messagewindow in front upon returning to the app (although I might change it around). Thanks again for the Time suggestion, I doubt I would have thought of it.
|
|
|
|
|
I want to show an xmlnode in text box. Currently it shows the xmlnode with it's child nodes in one staight line like <a attrib="attr"><b>Some text</b></a>
I want to show it as
<a attrib="attr">
<b>Some text</b>
</a>
Thanks
|
|
|
|
|
|
It seems to be a read only property.
|
|
|
|
|
Following a link from that doc, I found this:
(reader is an instance of XmlReader)
reader.WhitespaceHandling=WhitespaceHandling.Significant
|
|
|
|
|
|
Load that XML you have into the DOM, using the XmlDocument class like this...
string XML="<this is="" your="" text="" xml="">";
//now load it into the dom
XmlDocument doc=new XmlDocument();
doc.Load(new StringReader(XML));
//Now it's in the DOM, just save it as an XmlNode
XmlNode node=doc.SelectSingleNode("a");
now just go
textBox.Text=node.OutterXml;
and there you have it. I just typed this out of my head so there might be small errors, but that's the general idea.
/\ |_ E X E GG
|
|
|
|
|
i need a textbox with body transparent.
I've found one here on codeproject.com but it constain some bug.
Can you show me another one?
Tnx.
|
|
|
|
|
Possible approaches
1. try to fix the bug
2. write to the author about the bug, first checking the forum on the article for prior reports
3. keep looking for more free code instead of looking at the partially working code you have in front of you, in case you may learn something along the way.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm beginer and I'd like to draw cube or sizalble voxel with DirectX.
Please help me!!!
|
|
|
|
|
If you have the DX SDK, you have samples that do this, and if you don't, you can't use DX yet anyhow.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm trying to implement an error report in my program so that when it crashes it pops up a dialog that allows you to fill in some information and then send it along through email. The problem that I'm having is when I debug the program in VS it crashes gracefully, just like it's supposed to. But when I run it as a standalone .exe it just errors as if there is no try/catch statement. This is what I have for my Main function. If there are any suggestions please let me know.
<br />
static void Main() <br />
{<br />
try<br />
{<br />
System.Windows.Forms.Application.EnableVisualStyles();<br />
System.Windows.Forms.Application.Run(new frmMDI());<br />
}<br />
catch(System.Exception e)<br />
{<br />
System.Windows.Forms.Application.Run(new frmErrorReport(e));<br />
}<br />
}<br />
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|
|
Put a messagebox showing the exception message as the first line of the catch. Perhaps in release mode, your debug dialog is throwing it's own exception, causing this problem ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I've already tried that and it doesn't even hit the dialog. When I run it in 'release mode' it won't even hit the 'end of try' dialog. It just errors. This is what I had.
<br />
static void Main() <br />
{<br />
try<br />
{<br />
System.Windows.Forms.Application.EnableVisualStyles();<br />
System.Windows.Forms.Application.Run(new frmMDI());<br />
System.Windows.Forms.MessageBox.Show("end of try");<br />
}<br />
catch(System.Exception e)<br />
{<br />
System.Windows.Forms.MessageBox.Show("start of catch");<br />
System.Windows.Forms.Application.Run(new frmErrorReport(e));<br />
System.Windows.Forms.MessageBox.Show("end of catch");<br />
}<br />
}<br />
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|
|
Fair enough, just checking assumptions. Does the error occur in both places ? i.e. if you deliberatly divide by zero, does it throw in debug/crash in release ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I deliberatly try to set an int equal to a textbox string. And of course it throws 'Input string was not in a correct format.' When I do this in debug mode it catches the error, shows my dialog and everything is fine. But if I do the same proceedure in release mode I get the dafult .NET error dialog and it doesn't show my dialog.
Rob
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|