|
By the way Heath, Could you explain about layered windows which WMP9 use? WHats that?
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
See the documentation for the SetLayeredWindowAttributes API in the .NET Framework SDK. This is, BTW, what the Opacity and TransparencyKey properties on the Form class use.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
I just noticed that you like to change colors rather often, huh?
- Nick Parker My Blog | My Articles
|
|
|
|
|
Eh , I thought you know the answer.
Nick Parker wrote:
I just noticed that you like to change colors rather often, huh?
Yap.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
Mazdak wrote:
Eh , I thought you know the answer.
Ok, I suppose. You could P/Invoke PtInRect and then check on in your MouseMove eventhandler if you are within the area you want to be for displaying the form. I'm sure the answer is much more complex but maybe this will help get you started.
[DllImport("user32.dll")]
static extern bool PtInRect([In] ref RECT lprc, POINT pt);
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hello
I'm write a little class based on a sample from VB on VS Help to write values in the configuration file.
<br />
public static void SetStrAppSetting(string setting, string Value)<br />
{<br />
System.Reflection.Assembly Asm = System.Reflection.Assembly.GetExecutingAssembly();<br />
string strConfigLoc = Asm.Location;<br />
string strTemp = strConfigLoc;<br />
strTemp = System.IO.Path.GetDirectoryName(strConfigLoc);<br />
System.IO.FileInfo FileInfo = new System.IO.FileInfo(strTemp + "\\" + Path.GetFileName(Application.ExecutablePath) + ".config");<br />
System.Xml.XmlDocument XmlDocument = new System.Xml.XmlDocument();<br />
XmlDocument.Load(FileInfo.FullName);<br />
<br />
System.Xml.XmlNode CnfNode = XmlDocument["configuration"];<br />
System.Xml.XmlNode AppSettingsNode = CnfNode["appSettings"];<br />
<br />
foreach (System.Xml.XmlNode Node in AppSettingsNode)<br />
{<br />
if (Node.Name == "add")<br />
{<br />
if (Node.Attributes.GetNamedItem("key").Value == setting)<br />
{<br />
Node.Attributes.GetNamedItem("value").Value = Value;<br />
break;<br />
}<br />
}<br />
}<br />
<br />
XmlDocument.Save(FileInfo.FullName);<br />
}<br />
The problem is that the code makes the right thing write values in myfile.exe.config, but the application loads the dynamic properties from the app.config of the project. How I can handle this ?
Thaks
Pedro E. Pasamar Vidal
|
|
|
|
|
app.config is not used by the default AppDomain when your exectuable is loaded. While you can add an app.config file to your project in VS.NET, it is renamed to yourapp.exe.config, where yourapp is the name of your executable, and placed in the target directory. This is what the executable loader in Windows for managed applications uses as the default when your .NET application is loaded.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I have two questions:
1. does anyone know what data structures (if any) can be marshaled from C# to C++ and vice versa?
2. Some suggested me COM wrapper classes. How can I find an example for such a thing?
Thanks!
|
|
|
|
|
You should really read the .NET Framework SDK documentation. Interop'ing correctly between managed and unmanaged code also requires some knowledge of both, like knowing that a LONG in unmanaged C/C++ is a 32-bit integer, so it is an int in managed code.
You can read more about interoperability by reading Interoperability with Unmanaged Code[^] in the .NET Framework SDK online in the MSDN Library.
Also, all the primitive types are marshalled automatically by the CLR. You can also marshal structs (though nested structs are not supported by the CLR, nor are marshalling structs at all supported by the .NET Compact Framework (CF)) and reference types.
It also helps to know about the differences between reference and values type. For example, if you were P/Invoking a pointer to a struct (a value type), you'd use the ref or out keyword in both the method declaration as well as the parameter when calling the method. If you needed to pass a pointer to an interface, you wouldn't use either keyword because an interface is a reference type already.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I recently wrote a couple of lines of code which lets me move controls on my form just by dragging them with the mouse. Now that I can move controls around, I noticed something. A control with a transparent background will allow you to see the background of your form, but it still hides other controls on my Form. Furthermore, if I have different colors on my Form's background, I'll get a distortion momentarily on my control as it moves around. I'd like to be able to have movable controls without either of these issues. So my question is this:
Can I do something to my controls so that the transparent background actually works how I want it to?
Can I somehow change the region my control takes up so that I don't have this extra "space" around it? For instance, if I had a ball, why do I need the entire square?
Thanks for any help
|
|
|
|
|
DougW48 wrote:
Can I somehow change the region my control takes up so that I don't have this extra "space" around it? For instance, if I had a ball, why do I need the entire square?
Because every control is a window and uses a rectangular region. If you want to add a clipping region to your control, override OnPaint and set the Graphics.Clip property to a Region that contains only what you want (like a circle for your aforementioned control).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi all,
This may be a rather unusual question but as I'm a newbie in C#, I would be grateful if someone can please elaborate. Well, what I want to know is that why is the components variable added everytime in the class even when it is not used anywhere else. Every class generated using the Designer in VS.NET adds this variable in the class. Why? What is the purpose?
Thx,
Gurmeet BTW, can Google help me search my lost pajamas?
My Articles: HTML Reader C++ Class Library, Numeric Edit Control
|
|
|
|
|
you should add all your disposable items to the components IContainer.when calling IContainer.Dispose() it will call Dispose() on all the components it contains. Its merely there for ease of use, like the Events protected property in COntrols.
|
|
|
|
|
hi,
I've been coding this PieChart control all day now, just couldn't get it to work, if you know how to write a custom control, plese help me.
The main problem I have here is at the OnPaint() the PieChart doesn't draw all the pies except the first pie. What am I missing on writing a custom control here?
Complete codes are below or you can download the project here
PieChart.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
using System.Data;
using System.Windows.Forms;
namespace ColorControl.Controls
{
public class PieChart : System.Windows.Forms.Control
{
private PieChartItemCollection _Items = new PieChartItemCollection();
public PieChart()
{
base.Size = new Size(200, 200);
SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.ResizeRedraw |
ControlStyles.DoubleBuffer |
ControlStyles.UserPaint,
true
);
}
public PieChartItemCollection Items
{
get
{
return _Items;
}
set
{
_Items = value;
this.Invalidate();
}
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
int valueSum = 0;
int startDegree = 0;
int sweepDegree;
foreach (PieChartItem item in _Items)
{
valueSum += (int)item.Value;
}
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle rect = new Rectangle(ClientRectangle.X, ClientRectangle.Y,
ClientRectangle.Width - 1, ClientRectangle.Height - 1);
if (valueSum != 0)
{
foreach (PieChartItem item in _Items)
{
sweepDegree = (int)(item.Value / valueSum * 360);
SolidBrush brush = new SolidBrush(item.Color);
e.Graphics.FillPie(brush, rect, startDegree, sweepDegree);
if (_Items.Count > 1)
{
e.Graphics.DrawPie(new Pen(Color.Black), rect, startDegree, sweepDegree);
}
startDegree += sweepDegree;
}
}
e.Graphics.DrawEllipse(new Pen(Color.Black, 2), rect);
}
}
}
PieChartItem.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace ColorControl.Controls
{
[DefaultProperty("Value")]
public class PieChartItem
{
private Color _Color;
private string _Text;
private int _Value;
public PieChartItem()
{
_Color = Color.Red;
_Text = "Item";
_Value = 0;
}
public Color Color
{
get
{
return _Color;
}
set
{
_Color = value;
}
}
public string Text
{
get
{
return _Text;
}
set
{
_Text = value;
}
}
public int Value
{
get
{
return _Value;
}
set
{
_Value = value;
}
}
}
}
PieChartItemCollection.cs
using System;
using System.Collections;
namespace ColorControl.Controls
{
public class PieChartItemCollection : CollectionBase
{
public PieChartItemCollection() : base()
{}
public PieChartItem this[int index]
{
get
{
if (index >= 0 && index < base.Count)
return (base.List[index] as PieChartItem);
else
return null;
}
set
{
base.List[index] = value;
}
}
public void Add(PieChartItem item)
{
base.List.Add(item as object);
}
public void AddRange(PieChartItem[] items)
{
foreach (PieChartItem item in items)
{
Add(item);
}
}
public void Insert(int index, PieChartItem item)
{
if (index >= 0)
{
base.List.Insert(index, item as object);
}
}
public void Remove(PieChartItem item)
{
base.List.Remove(item as object);
}
public void RemoveAt(int index)
{
if (index >= 0 && index < base.Count)
{
base.RemoveAt(index);
}
}
public void RemoveAll()
{
for (int index = 0; index < base.Count; index++)
{
base.List.RemoveAt(index);
}
}
public bool Contains(PieChartItem item)
{
return base.List.Contains(item as object);
}
public int IndexOf(PieChartItem item)
{
return base.List.IndexOf(item as object);
}
}
}
There is also a small problem is that all "Pies" of PieChart have the same color, I will solve this as soon as I solve the previous problem.
Thank!!!
|
|
|
|
|
You should use Matrix transforms to rotate the drawing "canvas".
|
|
|
|
|
Can you explain please, I really want this control to work.
Thank!
|
|
|
|
|
I've developed an application and would like as part of the setup to place an Icon on the Desktop and the Quick Launch toolbar.
Ideally, I'd like to ask the client if they would like this to be done.
Thanks,
cb
|
|
|
|
|
You just need to create a shortcut to your application's EXE in the directories designated for quick launch and desktop shortcuts
\Documents and Settings\username \Application Data\Microsoft\Internet Explorer\Quick Launch
and,
\Documents and Settings\username \Application Data\Desktop
where username is the name of the current user
Gurmeet BTW, can Google help me search my lost pajamas?
My Articles: HTML Reader C++ Class Library, Numeric Edit Control
|
|
|
|
|
Thanks alot.
I did a search for th quicklaunch folder but it I could'nt find it. You set me on the correct path.
I had the Desktop nailed and will probably use "all users".
This all being said, how do you create these two short cuts within the setup routine????
Thanks,
cb
|
|
|
|
|
If you use the Windows Installer projects to deploy your application, open the file system editor view, right-click on the root folder ("File System on Target Machine") and add the "User's Desktop" (if not there already) ad "User's Application Data". To the latter folder, add sub-directories like Microsoft\Internet Explorer\Quick Launch".
Now, here's the trick. You'll need to compile the package and use something like Orca - an MSI package editor from the Windows Installer SDK - to go the Property table and create a new property called "ALLUSERS" and set the value to 2. You can't really do this in VS.NET's installer project because it frankly stinks. This is a cinche in professional packages like those from Wise Solutions[^] and Install Shield[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you.
You know for something as common as asking a user "Do you want a shortcut on your quick launch toolbar" and/or "Do you want a shortcut placed on your desktop" and then have them check the appropriate checkboxes should not be so difficult.
Since I own the community that this applications is going to be distributed to, I don't have to ask the questions.
I've downloaded Orca and will give it a whirl.
I've googled this to death and there isn't much out there.
Thanks again.
cb
|
|
|
|
|
It's not difficult if you use the right tools. VS.NET is meant to be a simple deployment solution. If one is knowledgable about Windows Installer (I've been using it since 1.0 beta days and even beta test it for Microsoft) you can use tools like Orca. There's also commercial tools out there that make these sort of things easy. VS.NET is not a viable solution for anything other than installing files and running custom actions written in .NET using the Installer class (perhaps a few other things, though not much).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
What are the 'commercial tools' you mention?
cb
|
|
|
|
|
I already provided links to two of the most well-known commerical tools for Windows Installer packages in this thread, sorted in order of my personal preference and cost (ISFWI is WAY too expensive and slow to support features unlike Wise).
Microsoft MVP, Visual C#
My Articles
|
|
|
|