|
interesting results; thanks for posting !
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin
|
|
|
|
|
Message Removed
modified 18-Dec-15 10:25am.
|
|
|
|
|
hi,all:
This question has been bothering me for a long time.
I have some series in chart1, for exampe,i have 100 series, each series have 1 point(or more). And i need paint a rectangle when mouse move, so i have code as follows, but when i run it, the rectangle can not move it smoothly, it is so slow . And i found if series number is less than 10, it maybe move fast.
how can i solve it,i have no idea.
public Form1()
{
InitializeComponent();
Series series1;
for (int i = 0; i < 100; i++)
{
series1 = new Series();
series1.Points.Add(new DataPoint(i, i)); //Just for example
series1.IsVisibleInLegend = false;
chart1.Series.Add(series1);
}
}
bool _isdown = false;
Rectangle r=new Rectangle();
private void chart1_MouseDown(object sender, MouseEventArgs e)
{
_isdown = true;
}
private void chart1_MouseMove(object sender, MouseEventArgs e)
{
if (_isdown)
{
r.Width = 100;
r.X = e.X;
r.Y = e.Y;
r.Height = 100;
panel1.Invalidate();
}
}
private void chart1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen p = new Pen(Color.LightBlue);
p.Width = 2;
p.Color = Color.Red;
g.DrawRectangle(p, r);
}
|
|
|
|
|
First, your code leaks resources at an insane rate. Every time the Paint event is called you're creating a new Pen and not Disposing it. This will eventually cause Windows to crash.
Create the Pen once, outside the event handler and reuse it. Dispose it when your application closes.
Next, this runs slow because you're drawing 100 series on a chart! It wasn't really designed to do that and isn't optimized to handle that kind of a load.
Every time you move the mouse with the button down, the chart has to be redrawn to "unpaint" the rectangle that your painting and redraw the rectangle in its new position and dimensions. To make it worse, you only have one data point per series! The more points you add to search series the exponentially slower the painting will become.
The only solution you have is to not draw so many chart series.
|
|
|
|
|
actually ,i need plot 20 series with 400 points, but when i plot them in the chartarea, it's also slow when mouse move.
But if i put 20*400 points in one series, the mouse move is fast. But my requirement is 20 line-series, so i don't want one series's end point line to the other's begin point.
|
|
|
|
|
The only way to speed things up is to reduce the number of points you have to draw in the graph. 20 * 400 = 8000 points.
Now, the question is why are you drawing boxes on the chart?
|
|
|
|
|
oh,i need to meet ZoomIn function. When user is doing ZoomIn, he can see his mouse's trace through a various width and heigh rectangle when mouse is down.
|
|
|
|
|
When i plot in the chart, i found chart speed is slower than other soft. Now i think chartarea refresh is cost most of time, but some times i don't need to refresh background series, just need to use invalidate to call paint function.
So is there any method to stop backgound series refresh ,not refresh paint function content?
|
|
|
|
|
No, there isn't, and YES, you HAVE TO PAINT THE BACKGROUND, which means painting the entire chart area. It's the only way to "undo" the previous painting of your rectangle so it can be repainted with it's new coordinates and size.
|
|
|
|
|
oh, but why some other soft can work so fast? Maybe other language can good work for this?
|
|
|
|
|
The language used doesn't matter at all. What does matter is the design of your graphing component, which you didn't write. You're trying to adapt a graphing component that isn't designed to do the job you want to do.
If you make your own graphing component that also supports drawing boxes on it and is OPTIMIZED to support what you want to do, then you can get the speed out of it.
|
|
|
|
|
|
i want is that, when i fetch data from database then labels dynamically added to my form.
i have a code but this show only one data, i want total result of query generate automatically label and set data into label.
my code is .
`
con.Open();
DataTable table = new DataTable();
string sqlText = "SELECT DATEDIFF(DAY, [meas_duedate], GETDATE()) , meas_id, client_id FROM tlb_meas_master"
SqlCommand cmd = new SqlCommand(sqlText, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
}
lbl_date.Text = dr.GetValue(0).ToString();
lbl_mea_id.Text = dr.GetValue(1).ToString();
lbl_cli_id.Text = dr.GetValue(2).ToString();
}
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n" + ex.Message);
con.Close();
}
`please help me....
|
|
|
|
|
You already posted this in the QA section. Don't post the same question multiple times.
|
|
|
|
|
With above code it will only show you last record value as you iterate records with data reader object
modified 20-Sep-20 21:01pm.
|
|
|
|
|
Hello All,
i have command - Get-WmiObject -Query "select * from win32_printer" -ComputerName ""
I would like to use Textbox with c# instead type computer type manually. How can i accomplish it?
Thanks.
|
|
|
|
|
|
we have ecomerance site. we are trying to flipkart seller api. to display our products in flipkart.
i am unable get start with work. not getting idea how to call REST API with OAuth.
from flipkart site it is showing to call.
oauth/token?grant_type=client_credentials&scope=Seller_Api,Default
not having idea how to call from c#.Net
Please any guide or help how call rest api with oAuth in c#.Net
Thanks,
Raja Ramesh
raja
|
|
|
|
|
What is wrong with this code that is not updating my datagrid and consequentetly the data base table? Thank you for any help.
using (OdbcConnection connection = CreateConnection())
{
string CmdText = "update lojas set Bloqueado =@bloqueador, DataFim = @DataFim, Nome = @Nome where Id =@Id";
OdbcCommand cm = new OdbcCommand(CmdText, connection);
cm.CommandType = CommandType.Text;
connection.Open();
cm.Parameters.AddWithValue("@Id", grid_lic.CurrentRow.Cells[0].Value);
cm.Parameters.AddWithValue("@bloqueador",grid_lic.CurrentRow.Cells[3].Value);
cm.Parameters.AddWithValue("@DataFim",grid_lic.CurrentRow.Cells[4].Value);
cm.Parameters.AddWithValue("@Nome",grid_lic.CurrentRow.Cells[6].Value);
cm.ExecuteNonQuery();
|
|
|
|
|
There is no code here to update the datagrid. You would need to refresh it after the database has been updated. E.g. set the datasource to null and then rebind it or use a BindingSource.
If the database is not being updated by this query then debug it to ensure the value for Id matches what you have in your data
|
|
|
|
|
When I change the data in the cells of the DataGridView, and I debug, the values that are shown are the new ones, but at the end the DataGridView is not updated. Can you please give an example of possible code to complete what I already have? Thanks.
|
|
|
|
|
How do you populate the DataGridView? And how are you changing the data in the cells? By typing over what is there? What do you mean by "at the end" ... at the end of what?
|
|
|
|
|
By the end I mean after cliking in the button "upgrade" where this code is inserted. I change data by typing over what is in the cell.
I populate the datagrid this way:
using (OdbcConnection connection = CreateConnection())
{
OdbcCommand Command = new OdbcCommand("insert into lojas (NIF, Loja, bloqueado, DataFim, lastupdate, Nome) values (?, ?, ?, ?, ?, ?)", connection);
Command.CommandType = CommandType.Text;
Command.Parameters.AddWithValue("@N IF", grid_lic.CurrentRow.Cells[1].Value);
Command.Parameters.AddWithValue("@Loja", grid_lic.CurrentRow.Cells[2].Value);
Command.Parameters.AddWithValue("@Bloqueado", grid_lic.CurrentRow.Cells[3].Value);
Command.Parameters.AddWithValue("@DataFim", grid_lic.CurrentRow.Cells[4].Value);
Command.Parameters.AddWithValue("@lastupdate", grid_lic.CurrentRow.Cells[5].Value);
Command.Parameters.AddWithValue("@Nome", grid_lic.CurrentRow.Cells[6].Value);
Command.ExecuteNonQuery();
}
|
|
|
|
|
Ok - that code is not populating the datagrid it's updating the database - are you saying that the DataGrid is bound to the database?
You refer to this as a DataGrid - is this in an ASP page? In which case are you checking for PostBack?
|
|
|
|
|
The datagrid is bound to the database. This is the connection command:
private static OdbcConnection CreateConnection()
{
return new OdbcConnection("driver= {MySQL ODBC 5.1 Driver};server=192.168.19.78; database=licenciamento; uid=estagio; password=1234; option = 3 ");
}
It is not an ASP page, it is only windowsform.
|
|
|
|