|
I have other reasons for using 2.0. This is just a sample. I know that you can access amazon and yahoo from 1.0 and 1.1.
Like i said, it is only 2.0 that is giving the problem.
thanx, amir
|
|
|
|
|
I'd like to create some controls that have unusual shapes. i.e. Oval, Diamond, picture.
The problem is, all controls appear to be represented as rectangles.
How can I make a control a custom shape? There is no region or size map that I can see that determines what shape a control is, so where does the MouseOver event get it's information?
I was thinking of using some Region map to draw my control, and limit it's painting to that. But i'm not sure where to begin.
Failing this, i would have to create some kind of transparent control, but this leaves me with the problem of custom controls hiding controls they overlap with in transparent areas. I believe this is due to UserControls handling their own paint methods.
Any advice on where to start would be appreciated.
Cata
|
|
|
|
|
Use
GraphicsPath to definet the shape, then use control.Region to set the region shape.
Creating Bitmap Regions for Forms and Buttons[^] shows how
Gary
"A fellow with the inventiveness of Albert Einstein but with the attention span of Daffy Duck."
Tom Shales talking about Robin Williams
|
|
|
|
|
hello,
My Web Service accesses to a MS SQL database to store and retrieve data from it.
but to store data, first I must to create programatacally the database and the tables. My question is what is the best way to do this? where is the best place to put the code which do this? In the beginning of each Web method (if the database and the tables do not exist, of course) or there is a common place to create or to initialize data, structures, systems, connections, etc.?
thanks in advance.
|
|
|
|
|
Actually, the best way to do it is to run the SQL script that creates everything either ahead of time, or when the Web Service is installed. Checking for the existance of the database on every call is very unecessary and just wastes time and resources doing the checks for something will only be done once.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
pelos wrote:
first I must to create programatacally the database and the tables. My question is what is the best way to do this?
Don't forget to add data. Aside from what Dave said I think you may be confusing two aspects of the software development lifecycle. You can manually type the DDL to create your database, tables and insert data into or you can use the visual tools that popular RDBMS provide. The purpose of web services is to allow a tranparent transport protocol regardless of operating system for data flow. Does that make sense?
- Nick Parker My Blog | My Articles
|
|
|
|
|
I've built myself a custom app wizard for VS.NET 2003. Everything is working great.
However I now want to use the wizard on another machine.
I currently have a hard-coded path I use in my AddFromTemplate call
proj = sol.AddFromTemplate("C:\\Program Files\\Microsoft Visual Studio .NET 2003\\VC#\\VC#Wizards\\DefaultWinExe.csproj", localDirectory, projectName, true);
Is there a way of determining where VS.NET is installed so that I don't have to hard-code the path. I've not seen a useable property in the DTE object model... but then again the documenation isn't the best in the world.
Any suggestions on where I can get the path whilst within my IDTWizard derived class.
Michael
CP Blog [^]
|
|
|
|
|
There's the DTE.FullName property that gives you the full path to the devenv.exe executable. You can use various Path methods (or just parse the string yourself) to get the base directory and then append the VC# directory.
You could also use the DTE.RegistryRoot key. That would give you a place to start to use the RegistryKey class that you could find the actual path to the VC# directory (just in case it was installed outside the VS.NET installation root somehow).
Finally, another way would be to use Process.GetCurrentProcess , then get the MainModule and get that return value's FileName , which is the full path to the executable hosting your code. This is a bit of a kuldge, though, but would work with other designers (like #develop, for example).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
There's the DTE.FullName property that gives you the full path to the devenv.exe executable. You can use various Path methods (or just parse the string yourself) to get the base directory and then append the VC# directory.
I'll have a look at that one. Probably more reliable than directly reading the info from the registry which is my current solution.
thanks for the advice,
Michael
CP Blog [^]
|
|
|
|
|
System.RunTime.InteropServices.COMException : A device attached to system is not functioning
at System.DirectoryServices.Interop.IAds.SetInfo();
this happen when i try a C# program which add users to administrators group.
When i add to another group like print operators,guests...everything is fine.
Anybody know how to solve this?
|
|
|
|
|
This may seem like a stupid question, but is the account that the app is running under have Admin rights to the machine?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
it's using administrator account, and one more, do you know how to do operation delete object, move object starting by authenticate and authorize the user first..
for example we use a username and password to do such an operation, so that whether such operation can be completed or not depends on the permissions given to given username.
I found that the permissions is applied according to windows account that is currently logged on and using the program.
What i want is the program itself will have its authentication & authorization independent of what account is actually used to logged on to windows.
Thanks
|
|
|
|
|
Hi all,
I am currently working on a class that draws a Piechart and a legend.
The class offers the possibility to get a bitmap of the chart and to get a bitmap of the legend:
PieChartDataSource dataSource = new PieChartDataSource();
dataSource.Add(new PieSliceData("Running", 1841200, Color.Green));
dataSource.Add(new PieSliceData("Waiting", 290000, Color.Blue));
dataSource.Add(new PieSliceData("Blocked", 181000, Color.Yellow));
dataSource.Add(new PieSliceData("Interruption", 62000, Color.Orange));
dataSource.Add(new PieSliceData("Fault", 45000, Color.Red));
PieChart chart = new PieChart(dataSource);
Bitmap chartBmp = chart.DrawChart(new Size(800,600));
chartBmp.Save(@"d:\chart.bmp");
Bitmap legendBmp = chart.DrawLegend();
legendBmp.Save(@"d:\legend.bmp");
I currently trying to draw the legend and the chart in one bitmap. Currently the legend is drawn in the bitmap, but the chart's size is not decreased yet, so it always draw on top of the legend. Have to fix this later...
But now to my problem:
I can now get a bitmap of the chart with a legend
PieChart chart = new PieChart(dataSource);
chart.DrawLegendInChart = true;
chart.LegendPosition = Position.top;
Bitmap chartBmp = chart.DrawChart(new Size(800,600));
chartBmp.Save(@"d:\chart.bmp");
and I can also get a seperate bitmap of the legend:
Bitmap legendBmp = chart.DrawLegend();
legendBmp.Save(@"d:\legend.bmp");
Both code snippets work fine, but if I execute both snippets (one after the other)
PieChart chart = new PieChart(dataSource);
chart.DrawLegendInChart = true;
chart.LegendPosition = Position.top;
Bitmap chartBmp = chart.DrawChart(new Size(800,600));
chartBmp.Save(@"d:\chart.bmp");
Bitmap legendBmp = chart.DrawLegend();
legendBmp.Save(@"d:\legend.bmp");
then I get an exception in DrawLegend() method.
This call
graphics.DrawString(strText, m_FontLegend, blackBrush, iStartX, iStartY);
throws the exception:
TargetSite.DeclaringType: System.Drawing.Graphics
TargetSite.Name: CheckErrorStatus
Message: Invalid parameter used
But how is it possible that this code works if I call it without drawing the chart with legend before?
I appreciate any help solving this problem!
Here is the complete code of my Piechart:
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections;
namespace Charts
{
#region enums
public enum Position{top, bottom, left, right};
#endregion
public class PieSliceData
{
#region fields
string m_strName;
double m_dValue;
Color m_Color;
#endregion
#region constructors
public PieSliceData(string strName, double dValue, Color color)
{
m_strName=strName;
m_dValue=dValue;
m_Color=color;
}
#endregion
#region properties
public string Name
{
get
{
return m_strName;
}
}
public double Value
{
get
{
return m_dValue;
}
}
public Color SliceColor
{
get
{
return m_Color;
}
}
#endregion
}
public class PieChartDataSource
{
#region fields
ArrayList m_List;
#endregion
#region constructors
public PieChartDataSource()
{
m_List = new ArrayList();
}
#endregion
#region methods
public void Add(PieSliceData sliceData)
{
m_List.Add(sliceData);
}
public void RemoveAt(int iIndex)
{
m_List.RemoveAt(iIndex);
}
public IEnumerator GetEnumerator()
{
return m_List.GetEnumerator();
}
#endregion
#region properties
public int Count
{
get
{
return m_List.Count;
}
}
#endregion
#region operators
public PieSliceData this[int index]
{
get
{
return (PieSliceData) m_List[index];
}
}
#endregion
}
public class PieChart
{
#region fields
PieChartDataSource m_DataSource;
Color m_BGColor;
float m_FontSizeLegend;
Font m_FontLegend;
bool m_bDrawLegendInChart;
Position m_LegendPosition;
#endregion
#region constructors
public PieChart(PieChartDataSource dataSource)
{
m_DataSource = dataSource;
m_BGColor = Color.White;
m_FontSizeLegend = 10.0f;
m_FontLegend = new Font("Verdana", m_FontSizeLegend);
m_bDrawLegendInChart = false;
m_LegendPosition = Position.bottom;
}
#endregion
#region methods
public Bitmap DrawChart(Size size)
{
Bitmap bitmap = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppArgb);
Graphics graphics = Graphics.FromImage(bitmap);
DrawChart(graphics, size);
return bitmap;
}
public void DrawChart(Graphics graphics, Size size)
{
SolidBrush brush = new SolidBrush(m_BGColor);
graphics.FillRectangle(brush, 0, 0, size.Width, size.Height);
brush.Dispose();
if(m_bDrawLegendInChart == true)
{
Size legendSize = CalculateLegendSize(graphics);
switch(m_LegendPosition)
{
case Position.top:
{
int iLegendOriginX = Convert.ToInt32((size.Width/2) - (legendSize.Width/2));
int iLegendOriginY = 5;
DrawLegend(graphics,new Point(iLegendOriginX,iLegendOriginY), legendSize);
}
break;
case Position.bottom:
{
}
break;
case Position.left:
{
}
break;
case Position.right:
{
}
break;
}
}
double total = 0.0;
for(int i = 0; i < m_DataSource.Count; i++)
{
total+=m_DataSource[i].Value;
}
float start = 0.0f;
float end = 0.0f;
double current = 0.0;
for(int i = 0; i < m_DataSource.Count; i++)
{
current += m_DataSource[i].Value;
start = end;
end = (float) (current / total) * 360.0f;
SolidBrush sliceBrush = new SolidBrush(m_DataSource[i].SliceColor);
graphics.FillPie(sliceBrush, 0.0f, 0.0f, size.Width, size.Height, start, end - start);
sliceBrush.Dispose();
}
}
public Bitmap DrawLegend()
{
Bitmap bitmap = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
Graphics dummyGraphics = Graphics.FromImage(bitmap);
Size legendSize = CalculateLegendSize(dummyGraphics);
bitmap = new Bitmap(legendSize.Width, legendSize.Height, PixelFormat.Format32bppArgb);
Graphics graphics = Graphics.FromImage(bitmap);
DrawLegend(graphics, new Point(0,0), bitmap.Size);
return bitmap;
}
public void DrawLegend(Graphics graphics, Point origin, Size size)
{
SolidBrush brush = new SolidBrush(m_BGColor);
graphics.FillRectangle(brush, origin.X, origin.Y, size.Width, size.Height);
brush.Dispose();
graphics.DrawRectangle(new Pen(Color.Black, 2), origin.X, origin.Y, size.Width, size.Height);
Brush blackBrush = Brushes.Black;
for(int i = 0; i < m_DataSource.Count; i++)
{
SolidBrush sliceBrush = new SolidBrush(m_DataSource[i].SliceColor);
graphics.FillRectangle(sliceBrush, origin.X + 5, origin.Y + 5 + (m_FontLegend.Height * i), 10, 10);
string strText = m_DataSource[i].Name +": "+ m_DataSource[i].Value.ToString();
int iStartX = origin.X + 20;
int iStartY = origin.Y + 1 + (m_FontLegend.Height * i);
graphics.DrawString(strText, m_FontLegend, blackBrush, iStartX, iStartY);
sliceBrush.Dispose();
}
blackBrush.Dispose();
}
private Size CalculateLegendSize(Graphics graphics)
{
float fRequiredSizeX = 0;
fRequiredSizeX = fRequiredSizeX + 20;
float fLongestString = 0.0f;
float fRequiredHeight = 0.0f;
for(int i = 0; i < m_DataSource.Count; i++)
{
SizeF stringSize = graphics.MeasureString(m_DataSource[i].Name +": "+ m_DataSource[i].Value.ToString(), m_FontLegend);
if( stringSize.Width > fLongestString)
{
fLongestString = stringSize.Width;
}
fRequiredHeight += stringSize.Height;
}
fRequiredSizeX += fLongestString;
return new Size(Convert.ToInt32(fRequiredSizeX), Convert.ToInt32(fRequiredHeight));
}
#endregion
#region properties
public Color BGColor
{
get
{
return m_BGColor;
}
set
{
m_BGColor = value;
}
}
public bool DrawLegendInChart
{
get
{
return m_bDrawLegendInChart;
}
set
{
m_bDrawLegendInChart = value;
}
}
public Position LegendPosition
{
get
{
return m_LegendPosition;
}
set
{
m_LegendPosition = value;
}
}
#endregion
}
}
|
|
|
|
|
It would help greatly to know what the exception type is and what the exception message reads.
You should also dispose of your Graphics object when done. You should always dispose any object when its class (or any base classes) implement IDisposable . A good way of ensuring this happens is using the using statement which disposes the object even if an exception is thrown:
using (Graphics g = Graphics.FromImage(bmp))
{
g.DrawString(...);
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It's a system.ArgumentException.
Message: "Invalid parameter used."
Stack Trace:
e.StackTrace " at System.Drawing.Graphics.CheckErrorStatus(Int32 status)\r\n at System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)\r\n at System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, Single x, Single y)\r\n at Charts.PieChart.DrawLegend(Graphics graphics, Point origin, Size size) in d:\\programmierung\\charting\\charts\\piechart.cs:line 281\r\n at Charts.PieChart.DrawLegend() in d:\\programmierung\\charting\\charts\\piechart.cs:line 247\r\n at ChartTestApp.Form1.startButton_Click(Object sender, EventArgs e) in d:\\programmierung\\charting\\charttestapp\\form1.cs:line 144\r\n at System.Windows.Forms.Control.OnClick(EventArgs e)\r\n at System.Windows.Forms.Button.OnClick(EventArgs e)\r\n at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)\r\n at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)\r\n at System.Windows.Forms.Control.WndProc(Message& m)\r\n at System.Windows.Forms.ButtonBase.WndProc(Message& m)\r\n at System.Windows.Forms.Button.WndProc(Message& m)\r\n at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)\r\n at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)\r\n at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.Run(Form mainForm)\r\n at ChartTestApp.Form1.Main() in d:\\programmierung\\charting\\charttestapp\\form1.cs:line 92" string
-------------------------------------------
The light at the end of the tunnel has been switched off temporarily due to budget problems...
|
|
|
|
|
what's the easiest way to enable the localization support to your form so that u can select the language u want from the menu and all the buttons texts and numerics change to the specidied language. do u have do create seperate forms for each of the language u support?
samitha
|
|
|
|
|
The first thing to do would be to read Developing World-ready Applications[^] in the .NET Framework SDK.
Creating different forms for different cultures is not only inefficient but incredibly inflexible. Doing things the right way, you need only add localization code (documented in the topic above) and for each language you want to support, override the strings, sizes, locations, etc. (as necessary - not all always need to be changed) in a satellite assembly. VS.NET can help you do this using the form designer (though it's important to understand what's happening, otherwise you're not actually developing anything) but it won't help you switch languages on the fly.
To do that, you have to break the designer. Change InitializeComponent so that it doesn't instantiate the controls (move instantiation in the top of that method to the constructor) and only makes calls to ResourceManager.GetObject (or, from the designer in VS 2005, ComponentResourceManager.ApplyResources ). When you switch languages, set Thread.CurrentUICulture to the CultureInfo you want (like new CultureInfo("de-DE") for the German language in the country of Germany) and call the method InitializeComponent again to reset the localized resources.
Do this after changing the form's Localized property to true , which will add the necessary code.
When localizing, localize all properties attributed with LocalizableAttribute(true) . The neutral language (the language in which the primary assembly was written, which should contain the neutral language resources) must contain all the localized resources (which is another reason for placing these in the primary assembly); the satellite assemblies can be added later and used automatically by .NET without changing a single line of code.
Fusion, the assembly binder, looks for satellite assemblies for the Thread.CurrentUICulture when binding an assembly. If no assembly is found, the neutral language resources in the primary assembly (the assembly that contains code - not just resources). In order to expediate this behavior, use the NeutralResourcesLanguageAttribute at the assembly level (prefixed with [assembly: ...] along with the neutral language (if developing assemblies in US English, you'd put "en-US" as the constructor parameter).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
In C# WinForm program, a AxWebBrowser control is used to design my own explorer. I want to replace the default context menu to my own. The below code can do this after 'DocumentComplete' event:
private void UseAlternativeDocumentContextMenu2()
{
mshtml.HTMLDocumentClass oDocument = (mshtml.HTMLDocumentClass)this.TheBrowser.Document;
oDocument.HTMLDocumentEvents2_Event_oncontextmenu += new mshtml.HTMLDocumentEvents2_oncontextmenuEventHandler( OnDocumentContextMenu2 );
}
private bool OnDocumentContextMenu2( mshtml.IHTMLEventObj e )
{
// Popup original contxet menu
if( e.shiftKey )
{
//e.returnValue = true;
return true;
}
// Popup my context menu
this.TheContextMenu.Show( this, new Point(e.x,e.y) );
e.cancelBubble=true;
//e.returnValue = false;
return false;
}
The 'TheContextMenu' is a standard C# context menu control.
The default context menu can be replaced successfully, but another issue is caused:
When any links in webpage is clicked by mouse left button, the links can't go to its linked webpage.
I can't find a way to solve this issue. Would you anyone can help me? I can provide entire code if you have an interest on it.
Icey
|
|
|
|
|
This is what the IDocHostUIHandler interface is for. You implement this and pass your implementation to the WebBrowser control. This allows you customization of the context menu correctly, as well as customizing other aspects of the WebBrowser control. Read Using MSHTML Advanced Hosting Interfaces[^] for more information.
Again, this is the correct way of changing the behavior of the WebBrowser control. It's why those interfaces are consumed by the WebBrowser control, and what many applications (like FrontPage, VS.NET, etc.) use (although they typically wrap MSHTML, not the WebBrowser control (which wraps MSHTML itself)).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
whats the code for printing a Windows Form?
cheers
SM
|
|
|
|
|
Hi everyone! I am a C# beginner here.
Need help in binding the data from DataView to MSChart after I filter out the specific data using DataView.RowFilter = "...";
Appreciate those who view this article and those who helped. Thanks!
|
|
|
|
|
MSChart is an ActiveX component - in no way related to .NET, so it doesn't understand the DataView type.
For starters, you really should try to avoid using ActiveX controls in .NET applications. There are plenty of native .NET components for charting, like ChartFX from SoftwareFX[^] that are reasonably priced. Using ActiveX controls means you have to actuall install and register the ActiveX control, where a properly written .NET library or application can be used without installation and easily deployed.
If you insist on using the MSChart control, then you must add your data series by enumerating the DataView , getting the DataRowView , and calling the appropriate method on the MSChart control:
DataView view = new DataView(dataTable1);
view.RowFilter = "LastName = 'Smith'";
foreach (DataRowView row in view)
There are plenty of examples of using the MSChart control in .NET on the 'net. Just try searching with google[^] or something.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks! I found it very useful. But I have another problem regarding this DataView.
Is it possible for the data after filtered in view.RowFilter to be stored inside a new dataTable ? Thanks!;)
Regards,
Kuan Wai Mun
|
|
|
|
|
Hello Gurus,
I just notice myself that it seems like DataGrid has no scrollbars. Did I miss something? How can I some how add scrollbars to DataGrid? Or is there an altenative control? If you have any information about this, I greatly appreciate.
Thanks a $million to you,
Khang Nguyen
|
|
|
|
|
the datagrid should have scrollbars if they are needed. Try putting info into a bunch of rows and see if they show up after you get past the end of the control.
- D
|
|
|
|
|