|
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
|
|
|
|
|
myDataView contains 1,204 rows.
// I set
myDataGrid.DataSource = myDataView;
At run-time, I got HScrollBar for myDataGrid with a little problem (can't see the last data column). But, I don't see the VScrollBar even though I have that many rows. I wonder if I have to use DataTable, instead of DataView, as something like this:
myDataGrid.DataSource = myDataTable;
Thanks,
Khang
|
|
|
|
|
Hy everyone!
I do want to add a webservice via https, because in the MSDN it says if I do so, my programm will talk via SSL to the webservice. Well our webservice is a Java Webserver and the webservice itself was created via the wsdl file, meaning I do access the wsdl for adding the web reference.
But doing so it says "connection to remote server was closed" and I do get a "403 Forbidden" error code.
Well I would have understood this error message if I couldn't reach the webservice, but there is something very strange: I am able to display the WSDL file via the Internet Explorer and via the wizard window in Visual Studio. But in the upper right window it displays the error messages and the "Add reference" button is grayed out. So I can't add the reference. It worked well via http, but it does not work via the https.
The only difference between these are the way we do access the webservice. Via http it looks like this:
http://ip:8080/servicedirectory/service?WSDL
via https it looks like this
https://ip:8443/servicedirectory/service?WSDL
where ip is the IP of the server containing the webservice, servicedirectory is the path to the webservice and service is the name of the webservice (well I know a very strange way to call a webservice service ).
But well I did what it said in the MSDN article but we were not able to fix the problem. We also had a look in the webloggs but there was nothing strange in there. Well I have to add the server is a tomcat server, but I think this shouldn't matter.
So if anyone of you has a solution to our tricky problem, please let us know, because well, we also thought about the certificate being necessary to being add to the reference, but the reference is just a kind of "symbolic link" to the service and it doesn't start it, it only creates the proxy class, does it?
Thanks!
Stephan.
|
|
|
|
|
You can use an HTTPS schema. If you're having problems generating the proxy class from the WSDL over HTTPS, do it using HTTP and in your code change the Url property of the web service proxy (a derivative of the WebClientProtocol class which defines the Url property) to your HTTPS schema. If the HTTPS virtual server requires a client certificate to connect via SSL, then make sure you add your X509Certificate to the ClientCertificates property, which is defined by the HttpWebClientProtocol (a derivative of WebClientProtocol and the actual base class for your web service proxy over HTTP/S).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Well, I did this, changing the Url from http to https.
But when I started invoking methods of the service this caused an exception together with the same error message like before
(The underlying connection was closed: Unable to connect to the remote server.
The remote server returned an error: (403) Forbidden.)
This means I am able to force https in the wsdl and the service proxy but then it thorws the exception when being invoked.
We have also tried to send a client certificate but my colleage didn't implement any requirement for a client certificate, meaning I should be able to use the service without a certificate.
The server just sends the certificate to encrypt the data being send with the servers public key.
Or did I missinterprete the definition of "virtual server"? Or do I need a certificate even if the server class he created didn't ask for one?
Stephan.
|
|
|
|
|
Unfortunately, I really don't know what you tell you. Using HttpWebRequest for an HTTPS connection is seamless (well, except for you in this case ). You should try writing a simple app that just downloads the content from any given URL and try connecting to a few other sites that implement HTTPS just to see if it's not something with your installation (although I can't imagine what that'd be).
Sorry I can't be of more help, but this should work and the fact that it works if you use IE or something else just compounds the problem.
Good luck!
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm trying to sort the data in my table, but no matter what I do with the Sort property, the resultant data does not change it's order at all. Does anyone know what I'm missing ? The authors of MSDN apparently missed it too, if there's a step I need to take...
DataSet comparisonDocs = facade.CompareMetadata(objectVids, elementPaths);<br />
DataView compSort = new DataView(comparisonDocs.Tables[0]); <br />
compSort.Sort="Title, Version/Major DESC, Version/Minor DESC";<br />
comparisonRepeater.DataSource = compSort;<br />
comparisonRepeater.DataBind();
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Is Version/Major supposed to be a field name? If so, try [Version/Major] . If you mean the Major field from the Version table, use . instead of / , although I'm not sure how that'd work in this case since your DataView is over a specific DataTable . If Version is a related table (and a DataRelation is established between the two), then use Child(RelationshipName).FieldName which should work.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Version/Major is indeed a field name. I didn't know that / was reserved in SQL, but I initially sorted by Title only, so I'm not sure that the [] is going to help ( it didn't sort by Title when I just specified 'Title' as the order by before ). Also, when I got the name wrong ( I'm not responsible for the schema ), and just put VersionMajor, it blew up on the basis that the column did not exist, so it presumably can see that Version/Major is a column name the way the code stands.
Have you used the sort property before ? It's supposed to work just the way that I'm trying to use it, isn't it ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
try:
DataView compSort = comparisonDocs.Tables[0].DefaultView;
|
|
|
|
|
Thanks, I did that. It turned out the sort was working, but the way the old code ( which I didn't write ) got it's details to render involved an array of objects instead of the data in the table...
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|