|
Cool!Enjoy!
|
|
|
|
|
Thanks anyway.. ..Cheers!
|
|
|
|
|
i did encounter the same problem as the guy have:
(from http://bytes.com/topic/c-sharp/answers/859828-c-transparent-control-problem)
Anybody can help?
thanks.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Hello there !
I'm developing a Windows appliciation that involves so called
"Transparent Controls". As you would probably know, the only ( as far
as i know ) way to achieve a fully transparent control in C# is to add
the so called "Transparent style" to your control
("WS_EX_TRANSPARENT"). There are numerous articles how to achieve this
and the method is ALMOST always one and the same:
1. protected override CreateParams CreateParams
2. {
3. get
4. {
5. CreateParams cp=base.CreateParams;
6. cp.ExStyle|=0x00000020; //WS_EX_TRANSPARENT
7. return cp;
8. }
9. }
10. protected override void OnPaintBackground(PaintEventArgs pevent)
11. {
12. //do not allow the background to be painted
13. }
14.
And that works fine! ( well .... at least all say that ..... and all
the articles say so ), but am i missing something or that method has
SOME SERIOUS problems that nobody can see ?
For example the Z-order. The following piece of code creates simply a
transparent control that draws a line across itself with a random
color:
1. using System;
2. using System.Collections.Generic;
3. using System.Text;
4. using System.Windows.Forms;
5. using System.Drawing;
6. namespace WindowsApplication16
7. {
8. public class HrisTranspControl : Control
9. {
10. private Pen _drawingPen;
11. public HrisTranspControl()
12. {
13. Random rnd = new Random();
14. this._drawingPen = new System.Drawing.Pen(new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(rnd.Next(0,255),rnd.Next(0,255), rnd.Next(0,255))),5);
15. }
16. protected override CreateParams CreateParams
17. {
18. get
19. {
20. CreateParams cp = base.CreateParams;
21. cp.ExStyle |= 0x00000020;
22. return cp;
23. }
24. }
25. protected override void OnPaintBackground(PaintEventArgs pevent)
26. {
27. // Do nothing
28. }
29. protected override void OnPaint(PaintEventArgs e)
30. {
31. base.OnPaint(e);
32. e.Graphics.DrawLine(_drawingPen, new System.Drawing.Point(0, 0), new System.Drawing.Point(this.Width, this.Height));
33. }
34. }
35. }
And so ... when u put few "line controls" on top of each other the
Z-ORDER goes to hell. You can't change it, its not corrent and it
changes randomly each time u select a random "line control".
I've tried A LOT of methods to fix that ( changing the z-order in
background, repainting the actual background because i think its
because the background is not drawn ... and so on ). None works. I'm
out of ideas and the worst part is i've almost finished the application
and right in the end i realize that bug and it kills me.
Please help !!!
The "line controls" were added in the order shows 1,2,3 , but the
Z-order appears to be different ( 1,3,2 ). In the current case "bring
to front" , "send to back" doesn't change the Z-ORDER
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
I want to add months and set the day as last day of that added month. I know i can do in the following way,
<br />
DateTime ldtManipulatedDate = new DateTime(1998,lintMonths,1).AddMonths(lintAddMonths);<br />
ldtManipulatedDate = new DateTime(ldtManipulatedDate.Year ,ldtManipulatedDate.Months,DateTime.DaysInMonth(<br />
ldtManipulatedDate.Year,ldtManipulatedDate.Months));<br />
The above code will first add months and then set the day as last day of that added month.
But i want this in one step as i am instantiating two times.
Please let me know how can i do it?
|
|
|
|
|
Hi,
from year and month:
DateTime dt=new DateTime(year, month, 1).AddMonths(monthsToAdd+1).AddDays(-1);
or from DateTime:
dt=dt.AddMonths(monthToAdd+1).AddDays(-dt.Day);
dt=dt.AddDays(1-dt.Day).AddMonths(monthToAdd+1).AddDays(-1);
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
modified on Wednesday, February 3, 2010 10:08 PM
|
|
|
|
|
Thanks Luc!!
Why didnt it strike in my mind...
|
|
|
|
|
you're welcome.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
fixed a bug
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
can anyone point me in the right direction on how to right click on a listbox entry and be able to rename it.
my project logs video clips in 60 sec files and stores them in a folder, i use filesystemwatcher to populate a listbox of with the file names as they are created
minute 1
minute 2
minute 3
and so on...
i want to be able to select a file and rename it so i can find that bit of video quicker
so far i got
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
//not sure what to add here
any help would be great
using visual studio 2008 c#
kenny
|
|
|
|
|
Hi,
1.
why use MouseDown? I would set SelectionMode.One, then use SelectedIndexChanged event and SelectedIndex property. Don't forget to check for >=0. Or better yet, use DoubleClick event, so user must double click to enter rename mode.
2.
how will you enter the new name? just typing at the ListBox? trough a TextBox?
and when do you want to rename? on hitting Enter? clicking a Button?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
would like to enter new name by just typing at listbox, dont want to double click as i use that for playing the video file
kenny
|
|
|
|
|
I would go with Scott's suggestion (context menu), hence use the SelectedIndexChanged event, and the KeyPress event.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
I would use a context menu.
When the user right-clicks and selects rename you can pop up a dialog asking for the new value to be input into a textbox.
When the user clicks OK you can just update the selected item text to the text they entered.
|
|
|
|
|
Does anyone know any way to set a process to be the foreground window in managed code, I have a Process object and need to set that process to be the front form. I was previously using the user32.dll function SetForegroundWindow(p.MainWindowHandle); , but I know have a requirement to use only managed code. Any ideas?
|
|
|
|
|
If the window is one in your application then you can call Activate(); on the instance and it will activate the form.
Why only managed code? Alot of the managed classes are just wrappers around the native stuff (or wrappers around managed wrappers!), calling API functions yourself is just the same so long as it is done correctly.
|
|
|
|
|
The process is not in my app, so the Activate(); trick wont work for me. The managed code is a microsoft certification requirement. It's fine if there are 3rd party assemblies in my project that call unmanaged code, but there cannot be any in any of the code I've written.
|
|
|
|
|
|
This has been stated quite a few times, format your code (using the pre tags) or it will just get ignored.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I'm trying to make a class that will simply put the progress bar in a loop (just to see how it works for learning purposes). I keep getting the following error though and I don't understand why.
error
Cross-thread operation not valid: Control 'progressBar1' accessed from a thread other than the thread it was created on.
here is the class code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class thread
{
private thread trd;
private ProgressBar _threadProgressBar;
public ProgressBar ThreadProgressBar
{
set { _threadProgressBar = value; }
get { return _threadProgressBar; }
}
public void startthread()
{
Thread trd = new Thread(new ThreadStart(this.ThreadTask));
trd.IsBackground = true;
trd.Start();
}
private void ThreadTask()
{
int stp;
int newval;
Random rnd = new Random();
while (true)
{
stp = ThreadProgressBar.Step * rnd.Next(-1, 2);
newval = ThreadProgressBar.Value + stp;
if (newval > ThreadProgressBar.Maximum)
newval = ThreadProgressBar.Maximum;
else if (newval < ThreadProgressBar.Minimum)
newval = ThreadProgressBar.Minimum;
ThreadProgressBar.Value = newval;
Thread.Sleep(100);
}
}
}
}
i'm calling it inside a windows form
with
public void callthread()
{
thread mythread = new thread();
mythread.ThreadProgressBar = progressBar1;
mythread.startthread();
}
thanks
|
|
|
|
|
Seems I wrote this[^] especially for you.
BTW: entering the error message in the Google search box usually leads to the solution right away.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Just for him? Do you take requests
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Mark Nischalke wrote: Do you take requests
Not normally. I do take hints though.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
haha thanks for taking the time and writing that article just for me. I feel special
Anyway, thanks again.
|
|
|
|
|
I have form with lot's of TextBoxes and also there is a lot of threads in my program that need to read content's of those TextBoxes (settings). Since I can't access controls from other threads, I decided to make special class that will hold all the settings, and if user changes some, control will invoke OnTextChanged event and change corresponding value in class. But if I use that approach there will be a lot of similar handlers tike this
private void txtCrap1_TextChanged(object sender, EventArgs e)
{
Settings.Crap1 = txtCrap1.Text;
}
What I want is to do something like this
private void SetUpControlBindings()
{
AddBinding(txtCrap1, Settings.Crap1);
AddBinding(txtCrap2, Settings.Crap2);
}
private void AddBinding(object control, object value)
{
}
private void UpdateValue(object sender, EventArgs e)
{
if (sender is TextBox)
{
}
}
But I can't find any pointers to variables in C# Any ideas how to do this?
Actually my program is a bit more complicated. I have not only textboxes, but CheckBoxes, NumericUpDowns etc. also I want my Settings class to hold some additional objects like Lists.
P.S. I can't use reflection since my code will be obfuscated after compilation
|
|
|
|
|
Hi,
it is pretty easy to create a method that returns the Text (or any other property) of a Control, even from an unrelated thread. Look for "Retrieving information from a Control" in this article[^].
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|