|
I am creating a UserControl that is a collection of Panles setup in a grid format. Each element of the grid is a Panel. I allow the user to add text to the panel in one of Nine locations described by the ContentAllingment Structure.
The Text object is nothing more than a Label control. I'm using a gradient brush to paint the background of each panel in the grid and am setting the background color or each Label control to transparent. My problem is on the initial paintof the control, all the grid boxes are transparent until I move the window or resize the control. If I choose to not set the Label control's background property to transparent, then all the Panels get painted correctly, but the Label controls llok bad because they have a flat backgournd color while it's parent Panel gas a gradient background color. My question is, why would nothing be getting painted until the control is resized or moved.
Here is the OnPaint handler override
protected override void OnPaint(PaintEventArgs e)
{
try
{
LinearGradientBrush brush;
brush = new LinearGradientBrush(
ClientRectangle.Location,
new Point(ClientRectangle.Left,ClientRectangle.Bottom),
this.BackColor,
ControlPaint.Light(this.BackColor));
e.Graphics.FillRectangle(brush, ClientRectangle);
brush.Dispose();
foreach(PanelLabel PL in LabelArray)
{
PanelLabel lb=null;
bool LabelFound=false;
foreach(Control ctrl in this.Controls)
{
if(ctrl is PanelLabel)
{
lb = (PanelLabel)ctrl;
if(lb!=null)
{
ContentAlignment CA = (ContentAlignment)lb.SimpleLocation;
if(lb.Text==PL.Text && CA==PL.SimpleLocation)
{
LabelFound=true;
break;
}
}
}
else
continue;
}
if(!LabelFound)
{
lb = new PanelLabel();
lb.Font=new Font(lb.Font,PL.TextStyle);
lb.Text=PL.Text;
lb.SimpleLocation=PL.SimpleLocation;
lb.BackColor=Color.Transparent;
}
lb.Bounds=SetLabelLocation(lb,PL.SimpleLocation,e.Graphics);
if(lb.Bounds!=Rectangle.Empty && lb.Bounds!=ClientRectangle)
this.Controls.Add(lb);
else
throw new Exception("Label bounds are empty");
}
base.OnPaint (e);
}
catch(Exception Err)
{
MessageBox.Show("On Paint Error:"+Err.Message);
}
}
Any ideas are appreciated
|
|
|
|
|
Don't I know I understood if well the problem, but and if you force the shot of the event?
protected override void OnResize(EventArgs e)
{
base.OnResize (e);
using (Graphics g = this.CreateGraphics())
{
this.OnPaint(new PaintEventArgs(g,
this.ClientRectangle));
}
}
protected override void OnMove(EventArgs e)
{
base.OnMove (e);
using (Graphics g = this.CreateGraphics())
{
this.OnPaint(new PaintEventArgs(g,
this.ClientRectangle));
}
}
Marcelo Palladino
Brazil
|
|
|
|
|
(DR["Name"] is DBNull) vs (DR["Name"] == DBNull.Value)
I am curious as to which has better performance?
Thanks.
|
|
|
|
|
Neither. DBNull is a singleton class, the sole instance of which is returned by DBNull.Value . The code generated by the is and == operators is exactly the same.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello all
I need to search about space in string i tryed indexof but i dont know the space Code.how can i do this
regards
Hay
|
|
|
|
|
int index = mystring.IndexOf(" ");
Charlie
if(!curlies){ return; }
|
|
|
|
|
I want to drag and drop files onto my usercontrol. I want to know which eventhandler to write in this case and how to get file info in that handler?
Help please
|
|
|
|
|
This is a very simple thing to accomplish. Have you searched MSDN??
Some helpers:
Control.AllowDrop - Gets or sets a value indicating whether the control can accept data that the user drags onto it.
Control.DragDrop Event - Occurs when a drag-and-drop operation is completed. The event handler receives an argument of type DragEventArgs containing data related to this event. One of the properties of DragEventArgs is Data. Use it to get the IDataObject that contains the data associated with this event. Check for file drop, and use...
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
}
Just look at this:
MSDN link[^]
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|
|
Hi,
A few years back I read somewhere that websites should be designed to work with 800x600 resolution monitors. I, at the time, thought that this was a good idea, and used the same pattern in my software. It made sense to design software so that everyone can use it, including those that have older PCs and smaller monitors. However, as I am far along in my current project, I am running into problems. The biggest of these is that I'm running out of space on the screen to display items. And, if the user is using a larger resolution, when they maximize the program, there is a lot of empty screen (for example my laptop's res is set to 1680x1050. A big difference from 800x600!) Perhaps it would be ok to design it to be optimized at, say, 1024x768? In that case those users with the lower resolution would just see scroll bars. My question is:
Is it ok to design software optimized on 1024x768 res and higher?
It sure would make a lot of things easier.
Thanks for your help.
Agent 86
|
|
|
|
|
You have to make sure you application is flexible for any size. Almost every decent computer out there support 1024x768 and higher. However, many user prefer to set their display to 800x600 - dont ask me why. Don't forget that a lot of people (like me) that like higher resolutions.
.NET has support for anchoring and docking. Make sure you use those properly correctly. Your application should support a variety of screen resolutions.
Agent 86 wrote: The biggest of these is that I'm running out of space on the screen to display items.
To avoid cluttering problems use collapsible panels and tab controls.
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|
|
Hi,
I want to build a C# utility that will show a list of computers connected to a particular DCOM server. The DCOM server and clients are all written in C++.
This utility could be launched on any client or the server, and be able to tell which client's were connected to the server. I'm hoping that the server keeps a list of active DCOM connections that it has, and its something that I could read up and display in a GUI.
Any ideas on if this is possible, without resorting to packet sniffing to find out which clients are connected?
Thanks,
Kevin
|
|
|
|
|
I tried to work with the Eventpool (http://www.codeproject.com/csharp/EventPool.asp).
But I have a problem with the debugger:
...
Delegate[] delegates = del.GetInvocationList();
foreach(Delegate sink in delegates)
{
try
{
sink.DynamicInvoke(args);
}
catch(Exception e)
{
Trace.WriteLine(e.Message);
throw(e);
}
}
...
The following code is in another project:
...
private void method1(object sender, EventArgs e)
{
System.Diagnostics.Debugger.Break();
Console.WriteLine("I was in method1");
}
...
Method1 will be called by the delegate. And it works!!! You can see the text at console. But the debugger don't stopp at the line "Console.WriteLine("I was in method1");", where a breakpoint was set.
Then I tried the line "System.Diagnostics.Debugger.Break();". Now the program stops at "sink.DynamicInvoke(args);". The line is green. It seems as if the debugger can't find the sourcecode for method1.
|
|
|
|
|
This question is article specific. You might get a better answer if you post your question there.
Generaly you need to make sure that you have application in debug mode (same goes for all the other assemblies that are loaded). Also makes sure that you have latest build of all assemblies - otherwise your lines might not match up.
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|
|
In addition to what Alex Said, also make sure the assembly you are trying to debug actually what you are debugging. The assembly Debug Mode (in the project properties -> Configuration Properties -> Debugging -> Debug Mode) needs to be set to the 'Wait to attach to an external process' option. , The 'Start Application' should be the name of the 'caller' .exe. If the assembly is in the same solution as the 'caller', then it needs to be the active project in the solution.
You should also try to make sure that the assembly you are debugging is only running in a single thread (ie. the 'caller' has only instantiated one instance of the class within the assembly) for testing purposes. Otherwise you'll find that the breakpoint will get hit multiple times (hitting the F10 key to step through the code will result in you ending up on your breakoint again - albeit in a different instance)
Hope this helps,
Stefan
|
|
|
|
|
Thanks for the aswers, but it still does not work.
I had forgotten to write:
When I call the eventshelper directly, the debugger is doing fine.
When I call the eventshelper with the eventpool, the debugger don't stopps.
|
|
|
|
|
I created a Web Service that has a method that takes string arrays for ex:
public void CalculateModel(string[] stringList1, string[] stringList2)
{
//code here
}
When I add this web service as a web reference to my C++ application it generates a proxy class, in the proxy class it displays the array parameters like this:
BSTR* stringList1, int __stringList1_nSizeIs,
BSTR* stringList2, int __stringList2_nSizeIs,
Then it does the following: checks these pointers for NULL
if ( stringList1 == NULL )
return E_POINTER;
if ( stringList2 == NULL )
return E_POINTER;
So my question is how do I prevent the proxy file from adding these checks for NULL? because I do allow the user to pass in an empty string array which is defaulted to NULL on the C++ side.
Thanks
|
|
|
|
|
A check for NULL isn't going to hurt you, is it? It doesn't look like the wsdl.exe tool has an option like this.
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|
|
Yes, it does effect me the check for NULL because it returns if the array is NULL & does not continue processing the data.
|
|
|
|
|
Yes, it does effect me the check for NULL, because it returns if the array is NULL & does not continue processing the data.
|
|
|
|
|
Hi,
I have a timer that I want to run in the main frame of my windows HMI application to execute a complex operation.
I chose a System.Windows.Forms.Timer timer so that it'll run on the main application thread.
I added a tick event :
this.timerPlot.Tick += new System.EventHandler(this.timerPlot_Tick);
and the timer woks fine on calls to timerPlot.Start() and timerPlot.Enable=true.
But... when I try to start the timer from a seperate thread in the application the timer function timerPlot_Tick is never called!!!
Does anyone know the reason why a timer can not be started from a sperate thread?
Thanks.
avivhal
|
|
|
|
|
As MSDN states: "This Windows timer is designed for a single-threaded environment where UI threads are used to perform processing. It requires that the user code have a UI message pump available and always operate from the same thread, or marshal the call onto another thread."
Use one of the other two Timer types. Here you find a short overview on timers.
www.troschuetz.de
|
|
|
|
|
Hi,
I am looking for a way to write Excel spreadsheets in a c# program without having Excel installed on the computer. Presently, the Excel sheets i create are in XML, but versions of Excel under 2002 don't support XML.
So, i am looking for articles or documentation that shows how i could do that
<pr>
Thanks!
|
|
|
|
|
Is the investment in time really worth the effort?
You better be sure before you tackle this... Google - "Excel File Format"[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is there a way to go about identifing all running applications that have windows or dialog boxes open? I'm wanting to write myself a small application that can find all the open application windows & dialog boxes on my PC and move them to a specfic monitor when required.
|
|
|
|
|
try:
System.Diagnostics.Process[] myprocs = System.Diagnostics.Process.GetProcesses();
there's an overload where u can specify a machine name.
hope that's what you ment;)
there are no facts, only interpretations
|
|
|
|