|
Im 99% sure that the DrawToBitmap method will invoke the OnPaint method on the control and pass a graphics object containing the bitmap.
so if you draw the text outside of the OnPaint method, that code will not be triggered when calling DrawToBitmap.
How are you drawing the text?
Control.CreateGraphics?
|
|
|
|
|
This is how things are:
I have created a control - ExpressionPlotter . It is used to plot math graphs - they are drawn on the control. The control has a panel which contains the graphs' information. In the OnPaint method of the ExpressionPlotter is the method which draws the text - DisplayExpressionsText . In DisplayExpressionsText the panel is sized according to the text and then in the drawing of the text the method panel.CreateGraphics is used to obtain the Graphics class. When it comes to the screen shot the DrawToBitmap is called for the ExpressionPlotter control.
I tried to draw the text in the Paint event of the panel, but when i started the program, the panel didn't show.
Still learning...
|
|
|
|
|
I did it! I moved the resizing of the panel to the OnPaint . Then i moved the drawing of the text to the Paint event of the panel. When i want to draw the text now i only have to Refresh() the panel.
Still learning...
|
|
|
|
|
nike_arh wrote: in the drawing of the text the method panel.CreateGraphics is used to obtain the Graphics class.
That's your problem. That means that you are always drawing the text on the screen. Use the Graphics object that is supplied in the event arguments to the Paint event.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Take a look at my article clickety in which I cover basic screen capture as well as capturing a specific area of the screen.
The source code is available for download from the article as well.
Regards
Guy
You always pass failure on the way to success.
|
|
|
|
|
When I open report by click button event - on the first time it opens, but on the second time (when I close report and open again), app breaks and appears error message:
System.InvalidOperationException was unhandled
Message="Invoke or BeginInvoke cannot be called on a control until the window handle has been created."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.BeginInvoke(Delegate method, Object[] args)
at Microsoft.Reporting.WinForms.ReportViewer.OnRenderingComplete(ProcessThreadResult result, PostRenderArgs data)
at Microsoft.Reporting.WinForms.ProcessThreadArg.OnComplete(ProcessThreadResult result)
at Microsoft.Reporting.WinForms.ProcessingThread.ProcessThreadMain(Object arg)
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart(Object obj)
I was not use threads and I cannot locate cause of error.
Thank you for any help.
|
|
|
|
|
Thank you for sharing the exception. Is there some code that goes with it?
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Thank you for answering. The main part report's code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using System.IO;
using System.Collections;
using System.Configuration;
using System.Management;
namespace DatabaseAccessWithADONET
{
public partial class ReportViewerFormIzv : Form
{
private static string ConStr =
ConfigurationManager.ConnectionStrings["DatabaseAccessWithADONET.Properties.Settings.PersonDatabaseConnectionString"].ConnectionString;
BindingManagerBase bindManager;
private bool PrintLayout = true;
bool loaded = false;
private CustomReportViewerMessages customMessages = null;
int current,max,tip;
public ReportViewerFormIzv()
{
InitializeComponent();
customizeReportViewer();
this.bindManager = this.BindingContext[this.cash.vReportBill, "IDBill"];
current = 0; tip = 0;
}
public void InitializeReport(string formName, string reportDisplayName, string reportPath, ReportDataSource reportDataSource)
{
this.Text = formName;
this.reportViewer.Reset();
this.reportViewer.LocalReport.DisplayName = reportDisplayName;
this.reportViewer.DocumentMapCollapsed = true;
this.reportViewer.LocalReport.ReportPath = reportPath;
this.reportViewer.Messages = this.customMessages;
this.reportViewer.LocalReport.DataSources.Add(reportDataSource);
this.reportViewer.RefreshReport();
}
private void reportViewer_RenderingComplete(object sender, RenderingCompleteEventArgs e)
{
if (!loaded)
{
this.reportViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
this.reportViewer.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.FullPage;
loaded = true;
}
switch (tip)
{
case 0:
this.reportViewer.LocalReport.DisplayName = "Cash bill "+ cmbBon.Text;
break;
case 1:
this.reportViewer.LocalReport.DisplayName = "Cheque bill " + cmbBon.Text;
break;
case 2:
this.reportViewer.LocalReport.DisplayName = "Sell Products " + cmbDate.Text.Replace(':','.');
break;
default: break;
}
}
private void ReportViewerForm_Load(object sender, EventArgs e)
{
using (SqlConnection veza = new SqlConnection(ConStr))
{
veza.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from vReportProduct order by Date desc", veza);
da.Fill(this.cash.vReportProduct);
vReportProductBindingSource.Sort = "Date DESC";
}
this.ReportProductTableAdapter.Fill(this.cash.ReportProduct);
cash.ReportBill.AcceptChanges();
using (SqlConnection veza = new SqlConnection(ConStr))
{
SemiQuery sq = new SemiQuery();
veza.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from vReportBill where Tip=0 order by Date desc", veza);
cash.vReportBill.Clear();
da.Fill(this.cash.vReportBill);
max = cash.vReportBill.Rows.Count;
tip = 0;
DataSet ds = new DataSet();
string reportSourceFile = sq.getProjectSourcePath() + @"\ReportGot.rdlc";
SqlDataAdapter dak;
if (cash.vReportBill.Rows.Count > 0)
{
dak = new SqlDataAdapter("SELECT * FROM ReportBill where IDBill=" +
cash.vReportBill.Rows[current]["IDBill"].ToString() + " order by Date desc", veza);
}
else
{
dak = new SqlDataAdapter("SELECT * FROM ReportBill where IDBill=0", veza);
}
dak.Fill(ds);
InitializeReport("Reports", "Cash Bill", reportSourceFile, new ReportDataSource("Cash_Cash", ds.Tables[0]));
this.bindingNavigator1.BindingSource = this.vReportBillBindingSource;
cmbBon.Visible = true;
lblBon.Visible = true;
cmbDate.DataSource = vReportBillBindingSource;
cmbDate.ValueMember = "IDBill";
cmbDate.DisplayMember = "Date";
this.cmbDate.FormatString = "g";
}
outlookBar1.SelectedButton = outlookBar1.Buttons[0];
panel1.Visible = true;
loaded = true;
this.reportViewer.RenderingComplete += new
Microsoft.Reporting.WinForms.RenderingCompleteEventHandler(this.reportViewer_RenderingComplete);
this.reportViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
this.reportViewer.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.FullPage;
this.WindowState = FormWindowState.Maximized;
max = cash.vReportBill.Count;
}
}
}
|
|
|
|
|
Hi,
I don't see any Invoke() or BeginInvoke(), and I don't see a button click handler either.
if you want effective help, show the relevant code, and use PRE tags. Read my sig.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
private void btnReport_Click(object sender, EventArgs e)
{
string reportSourceFile = getProjectSourcePath() + @"\ReportGot.rdlc";
ReportViewerFormIzv f = new ReportViewerFormIzv();
SqlConnection mConnection = new SqlConnection(ConStr);
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM ReportBill", mConnection);
DataSet ds = new DataSet();
da.Fill(ds);
f.InitializeReport("Reports", "Bill", reportSourceFile, new ReportDataSource("Cash_Cash", ds.Tables[0]));
f.Show();
}
And I nowhere use any Invoke() or BeginInvoke(). Whole code is pretty long for placing here.
|
|
|
|
|
Hi,
this may not be easy to locate.
The Invoke/BeginInvoke might not be yours; the ThreadStart probably is; and the
RenderingComplete must be yours.
I suggest you look at (all) the RenderingComplete handlers, and insert a try-catch block
in each of them, showing the entire exception if and when it occurs.
Use the debug build, watch for line numbers; tell Visual to always show line numbers.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
In my case, this error was caused because of an internal problem of the Reportviewer control, as the report rendering seems to be done by a separate thread.
Make sure that the "RefreshReport()" method is called only and just only when all the involved forms, controls, usercontrols, etc. are successfully initializated. In my case, I've called it on the "Shown" event of the ReportViewer's container form.
|
|
|
|
|
|
Hey Guys, Gals.
The following function I am quite stuck on... and hope you are able to help or provide some form of direction.
Basically I have been able to gather "logical drive details" about connected storage, however, with regards to the Serial Number, all I can acquire is the Volume Number, which is not unique to the physical hard drive itself.
I realise that in order to acquire the manufactures serial number I need to utilise the Win32_PhysicalMedia Class, (link below), however I haven't got the foggiest with whats going wrong
Does anyone have any ideas, code example that actually works?
I am using Vista or XP Professional, Visual Studio 2008.
This is what I have so far....
ManagementObjectSearcher Serial = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia")
foreach (ManagementObject Serials in Serial.Get()
{ combo_box.Items.Add(Serials["SerialNumber"].ToString()); }
Furthermore, the error I get is: NullReferenceException was unhandled, object reference not set to an instance of an object? Use the "new keywords" to create an object instance?
Cheers
Ian.
http://msdn2.microsoft.com/en-us/library/aa394346.aspx">http://www.eggheadcafe.com/forumtree.aspx?topicid=2
|
|
|
|
|
Hi,
you're on the right track, however not all objects returned by your WMI have a SerialNumber,
so Serials["SerialNumber"] would be null for them. You need a null-test; adding a few log
statements to your code would have told you what was going on.
BTW: you will probably also need new ManagementObjectSearcher("SELECT * FROM Win32_LogicalDiskToPartition");
in search of the drive number that corresponds to a particular drive letter.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hello everybody,
I am searching for a long time for a possibility to read some windows settings and display it in my C#-program.
I want to have the following options:
start-> run -> "dcomcnfg" -> components -> computer -> My Computer
now right click on "my computer" -> "Properties"
Now register "Com Security" and "edit Limits" Now I want to display all users and their rights. Only read, not write new rights (at the moment). My programm and myself are working with full admin rights, so there should be no problem with rights or something like that.
I do not know how I can get the user and their rights in my program. In the registry, there is value with a very long string. if I change the rights, the string will be changed too. But I do not know if the string represents the full users including their rights. And how I read (decode) it?
Is this the right way?
Can you help me?
Thanks for your answers!!!!
|
|
|
|
|
Hi,
I'm building a small command line app to test connections to remote system, just like with telnet. I need it to test both TCP and UDP connections.
TCP works fine but i don't know how to test UDP connections since they are stateless.
For testing TCP I'm using
<br />
System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)<br />
Then i use the Socket.Connect(hostName, portNumber) method to establish connection. If that succeeds and no exception is thrown, i count it as success.
If i try the same with UDP
<br />
System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)<br />
Using Socket.Connect(hostName, portNumber) method against a closed port doesn't throw an exception or any other sign of failure.
Can any one suggest a way to test UDP connections?
Thanks,
darthBug
Join the dark side of the code
|
|
|
|
|
Hi!
I don't think that you can test UDP "connections" that way simply because UDP is a connectionless protocol. Fire and forget - if the packet reaches the destination: fine, if not: bad luck.
You'd have to have a counterpart on the other side actually receiving the UDP packet and sending back a reply.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Thanks,
I was afraid that it would be the case. I guess i'll have to engineer something...
darthBug
Join the dark side of the code
|
|
|
|
|
Hi everyone,
I am writing a server-client chat application where I have a ServerObject that is subclassed from MarshalByRefObject and is created as a Singleton. This ServerObject is acquired by the client by the GetActivator() method. Now, I wanted to add an event handler that will be raised when someone joins or leaves the chat room. So, I have done something like this-
<br />
public delegate void OnUsersJoinEventHandler(object sender, EventArgs e);<br />
public delegate void OnUsersLeaveEventHandler(object sender, EventArgs e);<br />
<br />
public class ChatServerObject : MarshalByRefObject<br />
{<br />
public event OnUsersJoinEventHandler UsersJoin;<br />
public event OnUsersLeaveEventHandler UsersLeave;<br />
<br />
protected virtual void OnUsersJoin(EventArgs e)<br />
{<br />
...<br />
}<br />
<br />
protected virtual void OnUsersLeave(EventArgs e)<br />
{<br />
...<br />
}<br />
}<br />
<br />
public class ChatClient<br />
{<br />
public ChatClient()<br />
{<br />
object server_obj = Activator.GetObject(typeof(ChatServerObject), "tcp://...");<br />
m_chat_server_object = (ChatServerObject)server_obj;<br />
<br />
m_chat_server_object.UsersLeave += new ChatServerObject(this.UsersLeft);....Line(1)<br />
}<br />
}<br />
So, you get the idea. Now, when the code compiles okay but when the runtime executes the line (1) above it throws an exception. The exception says the following-
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll. Getting the InnerException wasn't much insightful either. I can send you the full string of the InnerException if you think it might be useful. I tried to create another class that was subclassed from MarshalByRefObject but wasn't Registered as WKO; and that works fine. So, perhaps it has something to do with the fact that my server object is a WKO. Any insights into this problem will be useful.
|
|
|
|
|
Hi,
Below is my question on a similar problem and no one has responded since the last 3 days and I have posted it twice.
Anyhow, I am started to think it has something to delegates or events--just an assumption, as I have a similar design and it causes exception.
My problem is below somewhere if you want to have a look. I am searching and if I find anything I will let you know and if you find anything, I'd appreciate the same.
|
|
|
|
|
Hi!
How is your server object instantiated? Singleton? Single Call? Published directly?
It seems there's a problem on the server side either with object creation or event registration.
Could you post the server's constructor and more details regarding the server and client remoting configuration (TypeFilterLevel etc.)?
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
In MDIParent Form, I am using tableLayoutPanel control with two colomns and I want to open a child form in second column of tableLayoutPanel at runtime. Is this possible? Please reply as soon as possible.
|
|
|
|
|
Dear All,
I need to administrator the Indexing Service via the Web Application,
I did find a component that i good for desktop but not for web application.
Any suggestion would be highly appericated.
Thank you!
Nauman
"Mess with the Best, Die like the rest"
|
|
|
|
|
How do i create a program using c# to block unwanted access to certain website such as playboy.com?
|
|
|
|
|