|
|
Hi!
The RichTextBox actually can do a lot more than you can access with the built-in methods and properties.
Underneath the .NET wrapper there's a RichEdit control (version 2) you can send windows messages to (read about rich edit control messages in MSDN) to achieve several nice effects like different kinds of numbering, underline styles, superscript/subscript and several others.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hello all,
I'm very frustrated with a bug that I can't seem to beat. I'm using Activator.CreateInstance to create an array of objects based on a sampleObject. Each instance of SampleObject contains a uniqueid which is generated randomly in the constructor. Something like this:
<br />
SampleObject sampleObject = new SampleObject();<br />
SampleObject[] array;<br />
<br />
<cut other stuff><br />
for (int i = 0; i < numberToCreate;i ++)<br />
array[i] = Activator.CreateInstance(sampleObject.GetType());<br />
<br />
<cut rest of code><br />
Now, when I run this in the VS debugger it works fine and I get a proper batch of unique objects. However, when I run the code outside of VS, all the objects have the same uniqueid!
Anyone out there have any idea what is going wrong or more importantly how to fix it
TIA
|
|
|
|
|
I tried something like this, and it worked perfectly. My thoughts:
1. Are you sure you're running the same code outside of VS? Maybe what you're running from outside is an older build.
2. You haven't shown us the ctor logic. When the ID is generated in the constructor, try printing it or logging it to a file, for debugging purposes.
3. Aggressive compiler optimization settings may be interfering with your program logic. Try running it without optimizations.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Hello Vikram,
Thanks for responding. I have verified that I am not running the latest build, etc. I also tried with optimisation disabled.
Here is my Constructor:
public class MyDerivedObject : MyBaseObject
{
public static int NUMBER_OF_DIMENSIONS = 2;
double uniqueID;
public MyDerivedObject() : base(NUMBER_OF_DIMENSIONS)
{
uniqueID = base.RandomGenerator.NextDouble(); // generate uniqueID
Console.WriteLine("uiqueID: " + uniqueID.ToString());
}
}
Thanks again
|
|
|
|
|
Just a hunch, but the problem could be with RandomGenerator. Maybe you're making the same mistake as I was here[^]
Did you try the logging part? Another angle for you: just for debugging, insert a
Thread.Sleep(500); as the last line of your MyDerivedObject's constructor.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Thank you Vikram! I'm not sure WHY it fixed the problem, but making the RandomGenerator static as suggested in the link you provided did the trick!
Many many thanks to you!
|
|
|
|
|
s0ren wrote: I'm not sure WHY it fixed the problem
That way, it only gets initialized once. If you create a random number generator inside the method, it is likely that the execution is so fast it gets seeded with the same value and generates the same 'random' numbers.
s0ren wrote: Many many thanks to you!
You're welcome; I'm glad I could help somebody.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Hello everyone!
I need to store such data:
Partitions(ex: english), Authors(ex: Shakespeare), Books(ex:Otello).
Ierarchy is Partitions->Authors->Books.
What is the best way to store data ?
I used a ArrayList -> SortedList -> SortedList and serialization.
I don't want to use SQL, because it cannot be installed on each computer, where this program will be used.
One nation - underground
|
|
|
|
|
For storing it, I would recommend XML. For displaying it, you can go for a TreeView.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Do you mean XML, you mean serialization ? What kind of structure should i use?
Is isn't it wery expensive to use a->s->s->? The number of elements won't exceed 1000.
One nation - underground
|
|
|
|
|
Dude, I thought your data looked something like this
English
Twain
Tom Sawyer
Huck Finn
Orczy
The Scarlet Pimpernel
Dawkins
The God Delusion
The Selfish Gene
Hindi
Premchand
Panch Parmeshwar XML is the best way to store this.
<yourRootTag>
<language name="English">
<author name="Twain">
<title>Tom Sawyer</title>
<title>Huck Finn</title>
</author>
Other authors go here...
</language>
Other languages go here...
</yourRootTag>
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Thanks for help. Can You tell me where can i read about this way of xml ? Read all Xml related articles ?
One nation - underground
|
|
|
|
|
Saikek wrote: Can You tell me where can i read about this way of xml ?
Here?[^]
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
|
Regards,
Satips.
Don't walk in front of me, I may not follow;
Don't walk behind me, I may not lead;
Walk beside me, and just be my friend. - Albert Camus
|
|
|
|
|
I just want to numeral.So I want to hold up any keys except numeral keys.
But I must not use NumericUpDown Control.
My code snippet:
switch (e.KeyCode)
{
case Keys.D0:
case Keys.D1:
case Keys.D2:
case Keys.D3:
case Keys.D4:
case Keys.D5:
case Keys.D6:
case Keys.D7:
case Keys.D8:
case Keys.D9:
case Keys.NumPad0:
case Keys.NumPad1:
case Keys.NumPad2:
case Keys.NumPad3:
case Keys.NumPad4:
case Keys.NumPad5:
case Keys.NumPad6:
case Keys.NumPad7:
case Keys.NumPad8:
case Keys.NumPad9:
break;
case Keys.Enter:
this.btnOK.Focus();
break;
default:
//hold up
break;
}
I do not know how write code at default.
please give me directions or other scheme ,thanks.
|
|
|
|
|
Hello,
I assume that you are handling the KeyDown event, and you whant to prevent non numerical inputs!
Then you have to set:
e.Handled = true;
Hope it helps!
All the best,
Martin
|
|
|
|
|
I writed
"e.Handled = true"
But it is noneffective.
it is anticly.
|
|
|
|
|
Hello,
jason_mf wrote: But it is noneffective.
YEs, sorry you also have to handle KeyPress!
But what I would recommend is inheriting your own NumericTextBox from TextBox.
public class NumericTextBox : System.Windows.Forms.TextBox
{
And override OnKeyPressed and OnKeyDown:
bool keydownHandled;
protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.D0:
case Keys.D1:
case Keys.D2:
case Keys.D3:
case Keys.D4:
case Keys.D5:
case Keys.D6:
case Keys.D7:
case Keys.D8:
case Keys.D9:
case Keys.NumPad0:
case Keys.NumPad1:
case Keys.NumPad2:
case Keys.NumPad3:
case Keys.NumPad4:
case Keys.NumPad5:
case Keys.NumPad6:
case Keys.NumPad7:
case Keys.NumPad8:
case Keys.NumPad9:
case Keys.Enter:
break;
default:
e.Handled = true;
break;
}
keydownHandled = e.Handled;
base.OnKeyDown (e);
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
e.Handled = keydownHandled;
base.OnKeyPress (e);
}
For the ENTER Key you can do the handling of KeyDown directly on the Form.
Hope it helps!
P.S.: Don't forget to care about "copy/paste"
All the best,
Martin
|
|
|
|
|
Hello,
An other way to validate the KeyPress for numeric input is:
const string validinput = "1234567890";
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (validinput.IndexOf(e.KeyChar) < 0)
{
e.Handled = true;
}
base.OnKeyPress (e);
}
All the best,
Martin
|
|
|
|
|
Here's my solution. Any comments are welcomed.
static bool isIISContainsCert() {
try {
DirectoryEntry W3C = new DirectoryEntry("IIS://Localhost/W3SVC");
foreach(DirectoryEntry entry in W3C.Children) {
PropertyCollection props = entry.Properties;
if( props["KeyType"].Value.ToString() == "IIsWebServer"
&& props["SSLCertHash"].Value != null ) {
return true;
}
}
} catch (Exception e) {
GTools.Logger.FileLog(e.ToString());
}
return false;
}
|
|
|
|
|
I have an arraylist that contains objects who themselves contain multiple properties. I would like to know is there are faster way than using a for loop to search through an arraylist to find the object whose certain property matches what I am looking for. An example of what I am currently doing is listed below.
for(int p = 0; p < SupplierItemDataStore.Count; p++)
{
if(stock.Code == ((XMLDefs.SupplierItem.SupplierItem)SupplierItemDataStore[p]).StockCode)
{
{
//Do stuff here
}
}
}
where stock is the object that is passed in and SupplierItemDataStore contains over 31,000 items.
|
|
|
|
|
I don't think that there will be more faster way.
<br />
foreach(XMLDefs.SupplierItem.SupplierItem sItem in SupplierItemDataStore){<br />
if(stock.Code = sItem.StockCode){<br />
}<br />
}<br />
There are a lot of C# gurus in our forum.. let's see what they say..
|
|
|
|
|
If you put the data in a HashTable with the stock code as key, you can locate the item very quickly.
If you use framework 2.0 you would use a Dictionary instead of a HashTable.
---
single minded; short sighted; long gone;
|
|
|
|