|
Playing with the ListView to try to get colored backgrounds.
ListViewItem lviGrossMargin = new ListViewItem(strListViewItem);
lvOptions.Items.Add(lviGrossMargin);
lviGrossMargin.SubItems[0].BackColor = System.Drawing.Color.Wheat;
lviGrossMargin.SubItems[1].BackColor = System.Drawing.Color.SpringGreen;
lviGrossMargin.SubItems[2].BackColor = System.Drawing.Color.YellowGreen; If I set lvOptions.Background, I color the entire background the identified color. But coding as above, I get the same result. Setting SubItems[0] to Wheat sets all SubItems. Setting SubItems[1] or [2] does nothing.
Playing with the SubItems[n].Text does apply the expected text in each column. If I play with ForeColor, same as BackColor occurs. [0] is recognized and applies it to all SubItems. It is only the colors that don't seem to work.
Is there a step I skipped that has to be done before manipulating colors or is it a feature that doesn't work correctly in VS Studio 2003?
|
|
|
|
|
|
That was the key. Thank you very much!
|
|
|
|
|
Hi,
I have a datagrid with a datatable, and am using the MouseMove event to make a tooltip pop up whenever the text in the cell is longer than the cell width. This works ok, but there's a problem. When the mouse enters the cell, the cell backcolor turns off-white/beige and the text is highlighted. (This also happens when I just click on a cell to select the row - at least until the I release the mouse button.) I do have a CustomDataTableStyle where I set
ts.BackColor = Color.Black;<br />
ts.ForeColor = Color.LightGray;
ts.SelectionBackColor = Color.Black;<br />
ts.SelectionForeColor = Color.CornflowerBlue;
Is there anything to prevent this from happening, or anything I can add that says that, upon MouseEnter the backcolor is black and the forecolor is cornflowerblue, or any other ideas?
Thanks!!!
Mel
|
|
|
|
|
Hello,
I created a simple Windows service using the code from http://msdn.microsoft.com/msdnmag/issues/05/03/SchedulingASPNETCode/default.aspx[^], I didn't change the code much accept the name of the service.
Installation goes perfect, but when the service is started, it stops right away giving me a message that the Serivce has no work to do so it is stopped.
Can anyone help me in determinig what the problem is here? All I am trying to do is create a simple timer service that will write to a text file at a given interval.
Thanks
Mike
<br />
using System;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Diagnostics;<br />
using System.ServiceProcess;<br />
using System.Configuration;<br />
using System.Globalization;<br />
<br />
using System.IO;<br />
<br />
namespace MyWinServices<br />
{<br />
public class InvokeMyWinService : System.ServiceProcess.ServiceBase<br />
{<br />
private System.ComponentModel.Container components = null;<br />
protected System.Timers.Timer timer;<br />
<br />
private double _intervalTest = 0;<br />
<br />
<br />
public static void Main() <br />
{<br />
ServiceBase.Run(new InvokeG6EntWinService());<br />
}<br />
<br />
<br />
public InvokeMyWinService()<br />
{<br />
InitializeComponent();<br />
CanPauseAndContinue = true;<br />
this.ServiceName = "MyWinServices";<br />
<br />
if( ! EventLog.SourceExists("MyWinServiceEventLog"))<br />
{<br />
EventLog.CreateEventSource("MyWinServiceEventLog", "MyWinServiceLog");<br />
}<br />
EventLog.Source = "MyWinServiceEventLog";<br />
EventLog.Log = "MyWinServiceLog";<br />
}<br />
<br />
<br />
private void InitializeComponent()<br />
{<br />
this.timer = new System.Timers.Timer();<br />
((System.ComponentModel.ISupportInitialize)(this.timer)).BeginInit();<br />
this.timer.Enabled = true;<br />
this.timer.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_Elapsed);<br />
this.ServiceName = "MyWinServices";<br />
((System.ComponentModel.ISupportInitialize)(this.timer)).EndInit();<br />
<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if (components != null) <br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
<br />
protected void InitializeTimer()<br />
{<br />
if (timer == null)<br />
{<br />
timer = new System.Timers.Timer();<br />
timer.AutoReset = true;<br />
timer.Interval = ReadAppSettingInterval();<br />
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);<br />
}<br />
}<br />
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)<br />
{<br />
RunCommands();<br />
}<br />
<br />
protected void RunCommands()<br />
{<br />
EventLog.WriteEntry(ServiceName + " Service ran ok");<br />
<br />
FileStream fs = new FileStream(@"c:\temp\MyWinServices.txt" , FileMode.OpenOrCreate, FileAccess.Write); <br />
StreamWriter m_streamWriter = new StreamWriter(fs); <br />
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End); <br />
m_streamWriter.WriteLine(" MyWinServices: Doing Job at: " + DateTime.Now + "\n"); <br />
m_streamWriter.WriteLine(" _intervalTest: " + _intervalTest + "\n"); <br />
m_streamWriter.Flush();<br />
m_streamWriter.Close(); <br />
}<br />
<br />
protected double ReadAppSettingInterval()<br />
{<br />
double interval = 600000, tempInterval;
if (ConfigurationSettings.AppSettings != null && <br />
ConfigurationSettings.AppSettings["IntervalMinutes"] != null)<br />
{<br />
string intervalMin;<br />
intervalMin =ConfigurationSettings.AppSettings["IntervalMinutes"];<br />
if (Double.TryParse(intervalMin, NumberStyles.Any,<br />
NumberFormatInfo.InvariantInfo, out tempInterval))<br />
interval = tempInterval * 60000;<br />
}<br />
<br />
_intervalTest = interval;
return interval;<br />
}<br />
<br />
protected override void OnStart(string[] args)<br />
{<br />
EventLog.WriteEntry(ServiceName + " 3 Service started");<br />
InitializeTimer();<br />
timer.Enabled = true; <br />
}<br />
<br />
protected override void OnStop()<br />
{<br />
EventLog.WriteEntry(ServiceName + " Service stopped");<br />
timer.Enabled = false;<br />
}<br />
protected override void OnPause()<br />
{<br />
EventLog.WriteEntry(ServiceName + " Service paused");<br />
timer.Enabled = false;<br />
}<br />
<br />
protected override void OnContinue()<br />
{<br />
EventLog.WriteEntry(ServiceName + " Service continued");<br />
timer.Enabled = true;<br />
}<br />
<br />
<br />
}<br />
}<br />
App.config
<br />
<?xml version="1.0" encoding="utf-8" ?><br />
<configuration><br />
<appSettings><br />
<add key="IntervalMinutes" value="5"/><br />
</appSettings><br />
</configuration><br />
<br />
|
|
|
|
|
Hi!
I'm not going to debug your code but tell you how you can do it yourself.
First of all, insert a call to System.Windows.Forms.MessageBox.Show("Attach a debugger and then press OK"); right at the start of OnStart() . Set a breakpoint immediately after the MessageBox. Compile and replace the new executable.
Then you'll have to allow the service desktop interaction (you can do this via the Services control panel).
If you start the service now, the MessageBox will pop up. Then you can attach your running VS to the process (you'll have to hurry a bit, before the start request for your service times out). Then you can klick OK in your MessageBox and the debugger will stop at the next breakpoint so you can step through the code and find out what goes wrong.
Regards,
mav
|
|
|
|
|
I'm writing an application where I want to register my own URL prefix with the system, so when the link is clicked it will pass the address to my application. Anyone have any idea how to do this in C#? I've been looking for information on it for the past hour and no luck
Thanks for your time
Peter
|
|
|
|
|
Have you checked out this article?
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
-- modified at 18:27 Friday 16th December, 2005
Sorry, it the caps lock. Changed "THIS ARTICLE" to "this article".
|
|
|
|
|
Thanks for the link. I can now add them, and it will work from the explorer address bar, but is there a way to get it to be recognised by the RichTextBox URL detection? Or does that use it's own list of URL prefixes?
I want it to work on other applications not just mine, so adapting the RichTextBox won't work for this.
Peter
|
|
|
|
|
I don't know. It should do what other application do: check the URL protocol getting used and ask the OS to handle it. For example, after adding the "note" protocol to my system, Firefox would open notepad.exe.
Dies your application accept the entire argument? For example, if you have the string "protocol:mother.of.pearl", then the string "protocol:mother.of.pearl" gets passed to the target application.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
It works when I enter it in an address bar fine. The problem is I want RichTextBoxes to detect the URL and highlight it as a link. The aim of which is to make it easy to send links through MSN Messenger. At the moment the only thing I can think of is somehow hooking into the RichTextBox for those windows and detecting it myself, but that sounds a bit too complicated than it needs to be.
Personally I can't see why the RichTextBox wouldn't use the registry to get the URLs, it makes a lot more sense than using an internal list, much more dynamic. But it seems to me that they are using an internal list.
Peter
|
|
|
|
|
Ah, now I understand your dilemma. If I have time this weekend, I will try to investigate a solution for you. No promises, of course! <smile />
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
If you have time that would be greatly appreciated. I can't find much, even went as far as to try disassembling the rich edit control to see how it detects URLs, but then I remembered I suck at assembly!
Peter
|
|
|
|
|
Hello. I've been working with a normal form widget, and after reading the article on Gradient Forms
http://www.codeproject.com/csharp/GradientForms_EasyWay.asp
I would like to morph the existing form without copying and pasting all the code (properties and events) already done.
Is this possible in VisualStudio? How?
Thanks in advance
Zopiro
|
|
|
|
|
can u use an inherited form control and inherit from the gradient form ?
regards,
g00fy
|
|
|
|
|
Hi I’m trying to create my own component under .Net Framework 2.0 in C#. I have a problem on reducing the surface where component can be drop.
In fact I would like to have the exact comportment of a winform : one part of my control would be a design surface like the title bar in a form (non accessible by the designer or other control) and an other part would be the container which add controls and where they can draw themselves.
Is there anybody who can help me?
|
|
|
|
|
I am assuming you are inheriting from ControlContainer which ultimately inherits from Control. So, you would need to override (from Control)
OnDragEnter
OnDragLeave
OnDragDrop
OnDragOver
and possibly
OnMouseMove
OnMouseHover
There is an example here: Control.DragOver Event[^]
|
|
|
|
|
You know, I am preparing an article on a replacement tab control that I just wrote that has this exact feature. Admittedly, it's authored in .NET 1.1, but I think the concepts will remain the same. (I haven't tried the .NET 2.0 stuff, yet.)
Here are the steps that I used to do this.
1. Override the DisplayRect to return the amount of area that you want the client to use.
2. Derive a new class from Control.ControlCollection that passes through requests for controls to the first child of your control.
3. Override Control.CreateControlCollection to return the class that you created in step 2.
4. Make the first (and only) child of your control a Panel with Dock = DockStyle.Fill.
If I'm not mistaken, that should do it. If that's not clear (and I hate to do this) you can always wait for my article. The working title is YaTabControl (Yet Another....).
Hope that helps.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hi
thanks for your post.
I'll be very interested on your article about tab control (I'll have to work on this problem in a few day).
About the problem of reducing the displayrectangle of my control. I tried the first point you saied
Curtis S. wrote: 1. Override the DisplayRect to return the amount of area that you want the client to use.
The result is :
public override Rectangle DisplayRectangle {
get {
Rectangle rec = base.DisplayRectangle;
return new Rectangle(
rec.X+(int)this._epaisseurBord,
rec.Y+(int)this._tailleBarTitre,
(int)(rec.Width-this._epaisseurBord*2),
(int)(rec.Height-this._tailleBarTitre-this._epaisseurBord));
}
}
(sorry for the french name of my properties )
The problem is I have no result. The breakpoint i used in debug mode show that this property is nerver acces.
At the end controls like button or label appear where ever they want on all the surface of my control.
The other point you told me are much more for a tabcontrol I think because the goal of my control is to have no control on it but can receive some.
Do you have an idea about why that doesn't work ???
Thanks for all
-- modified at 4:39 Saturday 17th December, 2005
|
|
|
|
|
That property will not get used unless the child has some kind of Dock style other than DockStyle.None . Unfortunately, that solution that I gave to you only works if all steps get done. Sorry. It was the only way that I could find to do what we both wanted.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Thank you very much.
I will try with a child panel with it dockstyle at fill. I hope that won't reduce the executive time.
I will told you if I find an other solution.
With the pleasure to read your artical very soon
|
|
|
|
|
|
Hi,
I sent the same post on the MSDN's forum and received an other way of doing what we both wanted. I didn't try it for the moment but wanted to keep you informed.
You can follow this URL : http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=172709&SiteID=1[^] to see the entire conversation but this is the answer of Jelle van der Beek.
"The zone in which components cannot be dropped is called the non-client area. There is no support in the .NET framework for the non-client area, but you can still control it by overriding the WM_NC* messages. Here is a piece of sample code that will set the non-client border to 10 pixels wide."
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Foo
{
public class SomeControl : Control
{
public SomeControl()
{
SetStyle( ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint, true );
}
protected override void WndProc( ref Message m )
{
switch( m.Msg )
{
case 0x0083:
if( m.WParam == IntPtr.Zero ){
RecalcNonClientArea( m.LParam );
}
else
if( m.WParam == new IntPtr(1) ){
RecalcNonClientArea( m.LParam );
}
break;
case 0x0085:
IntPtr hDC = WinApi.GetWindowDC( m.HWnd );
if( hDC != IntPtr.Zero ){
using( Graphics maing = Graphics.FromHdc(hDC) ){
}
WinApi.ReleaseDC( m.HWnd, hDC );
}
m.Result = IntPtr.Zero;
break;
}
base.WndProc( ref m );
}
private void RecalcNonClientArea( IntPtr lParam )
{
WinApi.NCCALCSIZE_PARAMS csp;
csp = (WinApi.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(
lParam,
typeof( WinApi.NCCALCSIZE_PARAMS ) );
csp.rgrc0.Top += 10;
csp.rgrc0.Bottom -= 10;
csp.rgrc0.Left += 10;
csp.rgrc0.Right -= 10;
Marshal.StructureToPtr( csp, lParam, false );
}
}
}
I hope that will help you...
All the best.
|
|
|
|
|
Cool, thank you very much! Happy coding.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hi
I used "System.Reflection.MethodBase.GetCurrentMethod().DeclaringType" in VB.NET to get the type of current class. But, if I try to use the same code in C#, it gives "class was expected" error and does not compile.
What is the equivalent of "System.Reflection.MethodBase.GetCurrentMethod().DeclaringType" in C#?
Please advice. Thanks
Pankaj
|
|
|
|