|
Hi,
I wrote my user control to have my transparent image button using Windows forms.
For transparency, I need this:
protected override CreateParams CreateParams<br />
{<br />
get<br />
{<br />
CreateParams cp = base.CreateParams;<br />
cp.ExStyle |= 0x00000020;<br />
return cp;<br />
}<br />
}
and this:
protected override void OnInvalidated(InvalidateEventArgs e)<br />
{<br />
<br />
Transparenz zu erhalten<br />
this.SuspendLayout();<br />
this.Width--;<br />
this.Width++;<br />
this.ResumeLayout();<br />
<br />
base.OnInvalidated(e);<br />
}
and this:
protected override void OnPaintBackground(PaintEventArgs pevent)<br />
{<br />
}
It's working fine, but it flickers a bit. If there wouldn't be the overridden createParams, I could use double buffering. But, in this case transparency wouldn't work.
Do you know a way to have transparency and double buffering?
Regards,
Andreas
|
|
|
|
|
I have a listbox that a user populates. I want to only allow single spacing to be added to the listbox.
CSharpian
|
|
|
|
|
You can use a regular expression with the pattern " {2,}" to replace multiple spaces with a single space.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks alot That was a huge help. This is how I used it.
str1 = " spaces morespaces ";
str2= Regex.Replace(str1," {2,}", " ");
I noticed that it replaced every occurence of a mulitple space with a single space even at the beginning and the end. So I used:
str2 = Regex.Replace(str2,@"^\s*(.*?)\s*$", "$1");
to trim all of the leading and trailing spaces
Result:
"spaces morespaces"
|
|
|
|
|
You can just use str2 = str2.Trim() instead of writing your own regular expression.
|
|
|
|
|
Hi,
How can I cancel the current printing job from the printer spool using C#.
I tried to search but found unuseful information.
Could you please help me.
Thanks
|
|
|
|
|
I have a puzzle that would require some assistance by somebody who is knowledgeable about control arrays. If I had a control array of say 85 elements, and I would like to shuffle them so that they are randomized, is there an efficient approach that would work?
Initially, I would suppose that there would be a requirement to have two arrays, and that each element would be randomly "popped" off of the first array and placed (I forget the other term) onto the second array. Then, the first array would be re-dimensioned so that there would be one fewer elements. The procedure would continue until the first array contains zero elements.
Alternatively, as I recall there is some kind of Array.Randomize() routine. This would permit the randomization of one array without the need for a second array. Could one of you array gurus kindly provide some additional information and to fill in the blanks?
Say that I have an control array like so:
private Control[] controlName = new Control[85];
-- modified at 23:20 Friday 20th October, 2006
|
|
|
|
|
The following should do what you want.
Control[] controlName = new Control[85];
private void Shuffle()
{
ArrayList list = new ArrayList(this.controlName);
Random rand = new Random();
int j = 0;
for (int i = 0; i < this.controlName.Length; i++)
{
j = rand.Next(list.Count);
this.controlName[i] = (Control) list[j];
list.RemoveAt(j);
}
}
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thank you, Stefan. Here is a little twist. The elements of the control array are dynamically instantiated at run time. Is it possible to randomize elements from the control array?
|
|
|
|
|
I'm sorry, but I don't understand your question. Could you rephrase it and/or explain in greater detail what you want to do.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi,
I want to control the show/hide to another program. I use Process to start the program and make the initial window status Minimized. then I use Process to get the program main window handle and use windows API showwindow to hide the program i just started.
Everything looks fine but one thing. some of the control's visible property (or event, like viisble changed) in the started program are not correct. for example, the button is visible in the GUI, you can click and execute something, but you always get false when you check (get) the visible value . but I can use windows Api like iswindowvisible to get the right visible value.
I can use API to set/get the right value, but the related event fired are not correct!!
BTW, the program I started is created by C# (VS 2005).
Does anyone have some idea about this.
Thanks a lot in advance.
Alan Shen
MCAD for .NET Version
^~^~^~^~^~^~^~^~^~^~^
Great idea is the beginging of success!
|
|
|
|
|
Hi folks
Is there any way of manipulating mp3 files such as:
1) extracting a part of a file (the actual data) and saving it somewhere
or
2) concatenating say two files to produce a third file and saving that file?
Kind regards
Ross
|
|
|
|
|
Well, if you aren't looking to do it in code - or want an easier way - check out Audacity - it is open source and does this - you just need the LAME MP3 encoder for it.
If you needed to do it in code and were not doing a commercial release, I think you could paste their code into your app to do this.
David
|
|
|
|
|
Hi,
I have an array (which may change in length each time) of numbers (employeeid) and I want to create a random generator function to return one these numbers.
The only parameters I will be receiving are the array of numbers and the array length.
I'm new to C# so any sample code would be appreciated.
Thanks.
|
|
|
|
|
public int GetRandomInt(int[] array, int length)
{
return array[new Random.Next(0, length)];
}
|
|
|
|
|
Thanks for your reply.
I'm getting the follwoing error..
Error 2 'System.Random.Next()' is a 'method' but is used like a 'type'
All I require is just one number returned from the array.
Does return array not return a list of arrays or does the Next method refine it to one number?
Pardon my ignorance.
|
|
|
|
|
Belfast Child wrote: Does return array not return a list of arrays or does the Next method refine it to one number?
array is your variable that was passed to the method. Using the square brackets is indexing the array to retrieve one of the members of the array. Since it is an array of int, you will return an int, which is what the method signature specified.
|
|
|
|
|
Cheers Guys.
Figured it out.
Here's a test on a click button for anyone else interested
public int GetRandomInt(int[] array, int length) <br />
{<br />
Random ranNum = new Random();<br />
return array[ranNum.Next(0, length)]; <br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
int [] intArray;<br />
intArray = new int[3] {123, 321, 666};<br />
int randumNum = GetRandomInt(intArray, 3);<br />
randomLabel.Text = (randumNum.ToString());<br />
}
|
|
|
|
|
You should use ranNum.Next(length) instead of ranNum.Next(0, length) as it produces random numbers within the same range and is almost 2 times faster.
Also I would suggest to retrieve the array length dynamically instead of using a fix value. Either do it when you call the GetRandomInt method or even remove the length parameter and do it inside the method.
int randumNum = GetRandomInt(intArray, intArray.Length);
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Belfast Child wrote: Error 2 'System.Random.Next()' is a 'method' but is used like a 'type'
Random r = new Random();
r.Next(...)
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
You have to put parantheses on the constructor, i.e. use "new Random()" instead of just "new Random".
It's better to create the Random object once, and use that throughout the program, than to create a new one for every random number. When you create a new object, it will be seeded from the system clock, so if you create them too closely in time, the randomness will be poor. Also it's a waste of resources to create more than one Random object.
---
b { font-weight: normal; }
|
|
|
|
|
hi
i want to copy large file and show progressbar to show operation.
what is your suggest for this subject ?
please give me an example for progressbar and copy file.
thanks
|
|
|
|
|
|
hi ..
Bekjong don't said me how to use Stream.BeginRead() and Stream.Beginwrite and show percantage of operation in progressbar .
and please give me an example how to use these methods.
thanks
|
|
|
|
|
Realistically, this is going to slow down your copy operation, by quite a bit. He's saying you can read how big a file is, then read and write it a bit at a time, giving you access to a progress bar in your own code.
The better answer IMO is, you can't do it. Why give a progress bar at the cost of doubling the time the operation takes ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|