|
Alright thank you, and at first i was just giving an example for you to follow. Didn't tell you what i was really trying to make. Sorry for the confusion.
|
|
|
|
|
Would it be better for me to change the Tree View to a Text Box, and have the text change when i click the button.
System.windows.form1.Textbox("Text"); ?
|
|
|
|
|
If you just need to display a different paragraph of text depending on the game selected, a TextBox would be sufficient. A TreeView control would be inappropriate and unnecessary. As your previous posts specifically talked about populating a TreeView control, I had made the (reasonable) assumption that you were dealing with some sort of hierarchical data structure. However your requirements are actually less complicated than that!
Paul Marfleet
|
|
|
|
|
I have as a ListBox item a reference to a ScrollingLine class, in which I override ToString() to return the part of text currently visible in a scrolling window. How do I get my ListBox to update its display of that string? Does it make a copy of the ToString() result of each item when initialising, or does it just not know to update and maybe I could invalidate it?
|
|
|
|
|
Hi Brady,
AFAIK a ListBox does not copy data to some internal location, it holds a collection of items,
and works from there.
If you create a reason for repainting it, you should call Invalidate() on the listbox;
you can use optional arguments to restrict the repainted area, but there is no "index"
input available.
You could try and use ListBox.GetItemRectangle to feed ListBox.Invalidate().
Alternatively (I have not tried this!), you could cause a specific item to be repainted
by changing one of its properties, Selected comes to mind. So you could try:
myListBox.SetSelected(!myListBox.GetSelected(index));
myListBox.SetSelected(!myListBox.GetSelected(index));
which toggles the item's selection back and forth, causing two repaints of that one item.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc, that didn't even work with an Invalidate after those lines. Thanks anyway, but for something this small, where the ListBox will never have more than say ten lines, I've resorted to re-populating it after each scroll operation. It actually looks perfectly smooth at this scale.
|
|
|
|
|
Sorry, my mistake, it would not compile like that. This is what I meant:
myListBox.SetSelected(index, !myListBox.GetSelected(index));
myListBox.SetSelected(index, !myListBox.GetSelected(index));
I know changing the selection of an item in a userdrawn ListBox causes a DrawItem event
on that item; but I have no experience modifying ListBox items other than adding/removing
some.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks, although that was an easy one to fix. Even after it compiled it didn't cause the control to refresh. It really looks quite OK just re-populating it each scroll event. These will only happen one character at a time, at the user's pace, not pixels at a machine pace.
|
|
|
|
|
I'm writing a geometic drawing program and thougt to be done, but as I started it and tried the functions nothing happened. Maybe it just a little problem I just don't see. The compiler says "built successfully". The functions should draw the named symbol on a white rect. The window is double buffered and is redrawn when the client size is changed.
Does anyone know a solution to this problem?
Thanks, and best wishes
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace Geo<br />
{<br />
public partial class Geo : Form<br />
{<br />
private System.Drawing.Image ImBuffer;<br />
private System.Drawing.Graphics GrDisplay;<br />
<br />
public Geo()<br />
{<br />
InitializeComponent();<br />
SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true);<br />
SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true);<br />
SetStyle(System.Windows.Forms.ControlStyles.DoubleBuffer, true);<br />
ImBuffer = new System.Drawing.Bitmap(this.ClientSize.Width, this.ClientSize.Height);<br />
GrDisplay = System.Drawing.Graphics.FromImage(ImBuffer);<br />
SolidBrush SBWhite = new SolidBrush(Color.FromArgb(255, 255, 255));<br />
GrDisplay.FillRectangle(SBWhite, 0, 0, this.ClientSize.Width, <br />
this.ClientSize.Height);<br />
}<br />
protected override void OnClientSizeChanged(EventArgs e)<br />
{<br />
base.OnClientSizeChanged(e);<br />
ImBuffer = new System.Drawing.Bitmap(this.ClientSize.Width, this.ClientSize.Height);<br />
GrDisplay = System.Drawing.Graphics.FromImage(ImBuffer);<br />
SolidBrush SBWhite = new SolidBrush(Color.FromArgb(255, 255, 255));<br />
GrDisplay.FillRectangle(SBWhite, 0, 0, this.ClientSize.Width,<br />
this.ClientSize.Height);<br />
}<br />
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
base.OnPaint(e);<br />
System.Drawing.Graphics g = e.Graphics;<br />
g.DrawImage(ImBuffer, 220, 25);<br />
}<br />
private void exitToolStripMenuItem1_Click(object sender, EventArgs e)<br />
{<br />
OnCancel(null, null);<br />
}<br />
private void OnCancel(object sender, CancelEventArgs e)<br />
{<br />
if (e != null)<br />
{<br />
e.Cancel = true;<br />
}<br />
}<br />
<br />
private void cbSelectDraw_SelectedIndexChanged(object sender, EventArgs e)<br />
{<br />
SetStat();<br />
SetLabels();<br />
}<br />
private void SetStat()<br />
{ <br />
if (cbSelectDraw.SelectedIndex == -1)<br />
{<br />
tbX1.Enabled = false;<br />
tbY1.Enabled = false;<br />
tbX2.Enabled = false;<br />
tbY2.Enabled = false;<br />
tbX3.Enabled = false;<br />
tbY3.Enabled = false;<br />
};<br />
if (cbSelectDraw.SelectedIndex == 0 || cbSelectDraw.SelectedIndex == 1 || cbSelectDraw.SelectedIndex == 2 ||<br />
cbSelectDraw.SelectedIndex == 5 || cbSelectDraw.SelectedIndex == 6)<br />
{<br />
tbX1.Enabled = true;<br />
tbY1.Enabled = true;<br />
tbX2.Enabled = true;<br />
tbY2.Enabled = true;<br />
tbX3.Enabled = false;<br />
tbY3.Enabled = false;<br />
};<br />
if (cbSelectDraw.SelectedIndex == 3 || cbSelectDraw.SelectedIndex == 4)<br />
{<br />
tbX1.Enabled = true;<br />
tbY1.Enabled = true;<br />
tbX2.Enabled = true;<br />
tbY2.Enabled = false;<br />
tbX3.Enabled = false;<br />
tbY3.Enabled = false;<br />
};<br />
if (cbSelectDraw.SelectedIndex == 7 || cbSelectDraw.SelectedIndex == 8 || cbSelectDraw.SelectedIndex == 9)<br />
{<br />
tbX1.Enabled = true;<br />
tbY1.Enabled = true;<br />
tbX2.Enabled = true;<br />
tbY2.Enabled = true;<br />
tbX3.Enabled = true;<br />
tbY3.Enabled = true;<br />
};<br />
}<br />
private void SetLabels()<br />
{<br />
if (cbSelectDraw.SelectedIndex == -1)<br />
{<br />
lbX1.Text="";<br />
lbY1.Text="";<br />
lbX2.Text="";<br />
lbY2.Text="";<br />
lbX3.Text="";<br />
lbY3.Text="";<br />
gbPoints.Text = "";<br />
gbPoint1.Text = "";<br />
gbPoint2.Text = "";<br />
gbPoint3.Text = "";<br />
};<br />
if (cbSelectDraw.SelectedIndex == 0)<br />
{<br />
lbX1.Text = "x_1=";<br />
lbY1.Text = "y_1=";<br />
lbX2.Text = "x_2=";<br />
lbY2.Text = "y_2=";<br />
lbX3.Text = "";<br />
lbY3.Text = "";<br />
gbPoints.Text = "Points";<br />
gbPoint1.Text = "Point 1";<br />
gbPoint2.Text = "Point 2";<br />
gbPoint3.Text = "";<br />
};<br />
if (cbSelectDraw.SelectedIndex == 1 || cbSelectDraw.SelectedIndex == 2)<br />
{<br />
lbX1.Text = "x=";<br />
lbY1.Text = "y=";<br />
lbX2.Text = "a=";<br />
lbY2.Text = "b=";<br />
lbX3.Text = "";<br />
lbY3.Text = "";<br />
gbPoints.Text = "Values";<br />
gbPoint1.Text = "Point";<br />
gbPoint2.Text = "Dimensions";<br />
gbPoint3.Text = "";<br />
};<br />
if (cbSelectDraw.SelectedIndex == 3 || cbSelectDraw.SelectedIndex == 4)<br />
{<br />
lbX1.Text = "x=";<br />
lbY1.Text = "y=";<br />
lbX2.Text = "d=";<br />
lbY2.Text = "";<br />
lbX3.Text = "";<br />
lbY3.Text = "";<br />
gbPoints.Text = "Values";<br />
gbPoint1.Text = "Point";<br />
gbPoint2.Text = "Diameter";<br />
gbPoint3.Text = "";<br />
};<br />
if (cbSelectDraw.SelectedIndex == 5 || cbSelectDraw.SelectedIndex == 6)<br />
{<br />
lbX1.Text = "x=";<br />
lbY1.Text = "y=";<br />
lbX2.Text = "d_x=";<br />
lbY2.Text = "d_y=";<br />
lbX3.Text = "";<br />
lbY3.Text = "";<br />
gbPoints.Text = "Values";<br />
gbPoint1.Text = "Point";<br />
gbPoint2.Text = "Diameters";<br />
gbPoint3.Text = "";<br />
};<br />
if (cbSelectDraw.SelectedIndex == 7 || cbSelectDraw.SelectedIndex == 8)<br />
{<br />
lbX1.Text = "x_1=";<br />
lbY1.Text = "y_1=";<br />
lbX2.Text = "x_2";<br />
lbY2.Text = "y_2";<br />
lbX3.Text = "x_3";<br />
lbY3.Text = "y_3";<br />
gbPoints.Text = "Points";<br />
gbPoint1.Text = "Point 1";<br />
gbPoint2.Text = "Point 2";<br />
gbPoint3.Text = "Point 3";<br />
};<br />
if (cbSelectDraw.SelectedIndex == 9)<br />
{<br />
lbX1.Text = "x=";<br />
lbY1.Text = "y=";<br />
lbX2.Text = "d_x";<br />
lbY2.Text = "d_y";<br />
lbX3.Text = "w_s";<br />
lbY3.Text = "w_e";<br />
gbPoints.Text = "Values";<br />
gbPoint1.Text = "Point";<br />
gbPoint2.Text = "Diameters";<br />
gbPoint3.Text = "Angles";<br />
};<br />
}<br />
<br />
private void btDraw_Click(object sender, EventArgs e)<br />
{<br />
Draw(PnUse(), SBUse());<br />
}<br />
<br />
private void Geo_Load(object sender, EventArgs e)<br />
{<br />
SetStat();<br />
SetLabels();<br />
SolidBrush UseBrush = new SolidBrush(Color.FromArgb(0,0,0));<br />
Pen UsePen = new Pen(Color.FromArgb(0,0,0));<br />
}<br />
private void Draw(Pen PnUse, SolidBrush SBUse)<br />
{<br />
switch (cbSelectDraw.SelectedIndex)<br />
{<br />
case -1:<br />
MessageBox.Show(this, "Select item you want to draw", "Geo", MessageBoxButtons.OK,<br />
MessageBoxIcon.Stop,<br />
MessageBoxDefaultButton.Button1);<br />
break;<br />
case 0:
this.GrDisplay.DrawLine(PnUse, ConvertX1(), ConvertY1(), ConvertX2(), ConvertY2());<br />
MessageBox.Show("A" + PnUse.Color.A.ToString() + <br />
"R" + PnUse.Color.R.ToString() + <br />
"G" + PnUse.Color.G.ToString() + <br />
"B" + PnUse.Color.B.ToString() +<br />
"X1" + ConvertX1().ToString()+<br />
"Y1" + ConvertY1().ToString()+<br />
"X2" + ConvertX2().ToString()+<br />
"Y2" + ConvertY2().ToString());<br />
break;<br />
case 1:
GrDisplay.DrawRectangle(PnUse, ConvertX1(), ConvertY1(), ConvertX2(), ConvertY2());<br />
break;<br />
case 2:
GrDisplay.FillRectangle(SBUse, ConvertX1(), ConvertY1(), ConvertX2(), ConvertY2());<br />
break;<br />
case 3:
GrDisplay.DrawEllipse(PnUse, ConvertX1(), ConvertY1(), ConvertX2(), ConvertX2());<br />
break;<br />
case 4:
GrDisplay.FillEllipse(SBUse, ConvertX1(), ConvertY1(), ConvertX2(), ConvertX2());<br />
break;<br />
case 5:
GrDisplay.DrawEllipse(PnUse, ConvertX1(), ConvertY1(), ConvertX2(), ConvertY2());<br />
break;<br />
case 6:
GrDisplay.FillEllipse(SBUse, ConvertX1(), ConvertY1(), ConvertX2(), ConvertY2());<br />
break;<br />
case 7:
Point[] ptDrawTriangle = {new Point(ConvertX1(), ConvertY1()), <br />
new Point(ConvertX2(), ConvertY2()), <br />
new Point(ConvertX3(), ConvertY3())};<br />
GrDisplay.DrawPolygon(PnUse, ptDrawTriangle);<br />
break;<br />
case 8:
Point[] ptFillTriangle = {new Point(ConvertX1(), ConvertY1()), <br />
new Point(ConvertX2(), ConvertY2()), <br />
new Point(ConvertX3(), ConvertY3())};<br />
GrDisplay.FillPolygon(SBUse, ptFillTriangle);<br />
break;<br />
case 9:
GrDisplay.DrawArc(PnUse, ConvertX1(), ConvertY1(), <br />
ConvertX2(), ConvertY2(), <br />
ConvertX3(), ConvertY3());<br />
break;<br />
default:<br />
break;<br />
<br />
}<br />
<br />
}<br />
private void Use()<br />
{<br />
switch (cbSelectDraw.SelectedIndex)<br />
{<br />
case 0:
case 1:
case 3:
case 5:
case 7:
case 9:
PnUse();<br />
break;<br />
case 2:
case 4:
case 6:
case 8:
SBUse();<br />
break;<br />
default:<br />
break;<br />
}<br />
<br />
}<br />
private short ConvertAlpha()<br />
{<br />
short sAlpha;<br />
short.TryParse(tbAlpha.Text, out sAlpha);<br />
return sAlpha;<br />
}<br />
private short ConvertRed()<br />
{<br />
short sRed;<br />
short.TryParse(tbRed.Text, out sRed);<br />
return sRed;<br />
}<br />
private short ConvertGreen()<br />
{<br />
short sGreen;<br />
short.TryParse(tbGreen.Text, out sGreen);<br />
return sGreen;<br />
}<br />
private short ConvertBlue()<br />
{<br />
short sBlue;<br />
short.TryParse(tbBlue.Text, out sBlue);<br />
return sBlue;<br />
}<br />
private short ConvertX1()<br />
{<br />
short sX1;<br />
short.TryParse(tbX1.Text, out sX1);<br />
return sX1;<br />
}<br />
private short ConvertY1()<br />
{<br />
short sY1;<br />
short.TryParse(tbY1.Text, out sY1);<br />
return sY1;<br />
}<br />
private short ConvertX2()<br />
{<br />
short sX2;<br />
short.TryParse(tbX2.Text, out sX2);<br />
return sX2;<br />
}<br />
private short ConvertY2()<br />
{<br />
short sY2;<br />
short.TryParse(tbY2.Text, out sY2);<br />
return sY2;<br />
}<br />
private short ConvertX3()<br />
{<br />
short sX3;<br />
short.TryParse(tbX3.Text, out sX3);<br />
return sX3;<br />
}<br />
private short ConvertY3()<br />
{<br />
short sY3;<br />
short.TryParse(tbY3.Text, out sY3);<br />
return sY3;<br />
}<br />
public void btUse_Click(object sender, EventArgs e)<br />
{<br />
Use();<br />
}<br />
private Pen PnUse()<br />
{<br />
Pen PnUse = new Pen(Color.FromArgb(ConvertAlpha(),<br />
ConvertRed(),<br />
ConvertGreen(),<br />
ConvertBlue()));<br />
return PnUse;<br />
}<br />
private SolidBrush SBUse()<br />
{<br />
SolidBrush SBUse = new SolidBrush(Color.FromArgb(ConvertAlpha(),<br />
ConvertRed(),<br />
ConvertGreen(),<br />
ConvertBlue()));<br />
return SBUse;<br />
}<br />
public void btDialog_Click(object sender, EventArgs e)<br />
{<br />
ColorDialog dialog = new ColorDialog();<br />
dialog.Color = Color.FromArgb(255, 255, 255);<br />
dialog.ShowDialog();<br />
tbAlpha.Text = dialog.Color.A.ToString();<br />
tbBlue.Text = dialog.Color.B.ToString();<br />
tbGreen.Text = dialog.Color.G.ToString();<br />
tbRed.Text = dialog.Color.R.ToString();<br />
}<br />
}<br />
}
|
|
|
|
|
someControl.InvalidateRegion();
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
If you mean, that some function definitions are made in the worng region, I checked that, but didn't find anything. May you tell me what do you exactly mean, so that I can check that again?
Thanks and best wishes
|
|
|
|
|
usually when you draw by overriding paint you need to tell the application when painting is required. This is done view the Invalidate and InvalidateRegion method that is inherited from the base class control. I was just throwing it out there as a possible avenue to consider since many of the custom drawing methods I do require calls to InvalidateRegion to work correctly and efficiently.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
I tried the invalidate methode but it didn' change anything expect for the fact that the drawn rect didn't fill up the client size as I want it. I don't think that this is the problem, I already used the double buffer in other projects without any problems.
|
|
|
|
|
I tried the invalidate method in another way and now it works
Thanks much
|
|
|
|
|
Hi all...
We are facing a strange oledb behaviour: here is the code,
<br />
oConn.Open();<br />
System.Data.Odbc.OdbcCommand oCmd = oConn.CreateCommand();<br />
<br />
oCmd.CommandText = "SELECT * FROM [" + this.strMandateNrOld + "A-PERS]";<br />
DataTable dtPers = new DataTable();<br />
dtPers.Load(oCmd.ExecuteReader());<br />
It works fine and it fills my DataTable, but when I analyze the content, I can see that some columns are not filled... In a table of 72 columns, 3 columns which content is DateTime and Char are blank, but we know that in the file they are not...
We tried changing the connection string, switching from ODBC to OleDb... but we always have the same problem...
Does somebody have any idea or suggestion?
|
|
|
|
|
It really depends on what your data source is. I worked with an ODBC connection to a PICK (IBM Universe) data source and had a similar problem. It ended up that the mapping of the view for ODBC in PICK was incorrect and had to be re-mapped. So depending on your data source, you may want to look at that is the first source.
Finally for testing purposes, you may want to use a generic third party query tool to see what is coming back from the connection. If it doesn't work in that tool, then you know that it is a problem on the data source end.
I have used the following tool with much success for troubleshooting. Query Tool ADO
Hogan
|
|
|
|
|
If I can understand, what I need to do is find the right connectionstring, right?
I downloaded the query tool you suggested, but whatever I do, I always get the same problem.
Now I may misunderstood your suggestion... what do you mean with remapping the datasource?
|
|
|
|
|
Joz,
What I mean is the following.
* Down the QTADO tool.
* Test your query to your datasource with the QTADO tool.
* If the query in your code is "SELECT * FROM customers WHERE CustomerID = 9", the put that exact query in QTADO and run it.
* If QTADO is missing the same columns that your program is missing, then there is most likely a problem with the Data Source or ODBC Driver.
* If you are using an older database like IBM Universe, you may have to remap your data a differently.
Hope this helps.
Hogan
|
|
|
|
|
I'm having a similar problem with an Excel file.
I’ve been trying to read in an Excel file using either a DataSet or DataTable with OleDbDataAdapter. Here’s the code snippet:
//Identify the data source Excel file
sLine = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
sLine += sFilePathAndName;
sLine += ";Extended Properties=Excel 8.0";
OleDbConnection con = new OleDbConnection(sLine);
con.Open();
sLine = "SELECT * FROM [PublishCalendarSpreadOneOff$]";
OleDbDataAdapter DataAdapt = new OleDbDataAdapter(sLine, con);
//Construct a data table to hold the data
DataTable DataTbl = new DataTable();
//Fill the data table with the spreadsheet data
DataAdapt.Fill(DataTbl); // ERROR this doesn't fill the data column if there's no data in the first row.
if (con != null) con.Close();
This ought to fill DataTbl with the spreadsheet data and does so with one problem. If the first row of data (not the column headers but the data) is blank in some cells the DataTbl has the column but never gets any data for the column. In the following illustration:
New Applied Margin Rate Previous Applied Margin Rate Percentage Change Tier New Discount rate
16,800 16,800 0.00% 100%
16,800 16,800 0.00% 100%
59,850 59,850 0.00% 1 100%
52,070 52,070 0.00% 2 87%
52,070 52,070 0.00% 3 87%
59,850 59,850 0.00% 4 100%
59,850 59,850 0.00% 5 100%
Is an Excel file. The DataTbl never gets any data for the “Tier” column apparently because the first data cell is blank. If I put any character in this cell it reads the file fine. Strangely, if I delete a first data cell in other columns, New Scanning Range for example, the remaining data reads fine. It’s not a cell formatting issue – I tested that several ways. I’ve spent some time web searching and haven’t found any solutions. Any clues on how to fix this?
|
|
|
|
|
Dear programmers,
I have the following question.
What is faster, C# or C++ if I have pure numerical calculations.
Are there any experiences?
Lets say, I want to invert (or multiply) "double-valued"-matrices of size 300 x 300 a lot of times and if I assume that both algorithmic versions (C# and C++) are using exactly the same algorithm
Kind regards
|
|
|
|
|
Tomerland wrote: What is faster, C# or C++ if I have pure numerical calculations.
Are there any experiences?
In my experience writing test code and observing the difference is much faster than posting a message and waiting for someone to reply. And that doesn't even take into account the reliability of the reply.
But seriously, this type of information should not be hard to find[^].
|
|
|
|
|
C++ is faster since it does not rely heavily on the .NET framework which takes up more memory which would resultingly slow your program.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Of course C++ is much much much faster!
(But if you are using C++.NET -by using .NET FCL- C++.NET actually is as slow as C#.NET!)
|
|
|
|
|
MohammadAmiry wrote: (But if you are using C++.NET -by using .NET FCL- C++.NET actually is as slow as C#.NET!)
Really? Not according to this article[^] written by someone on the C++ team, but you probably know better than him.
Another common misconception is that the same kind of superior performance on the .NET Framework can be attained regardless of the language you use—that the generated Microsoft intermediate language (MSIL) from various compilers is inherently equal. Even in Visual Studio .NET 2003 this was not true, but in Visual Studio 2005, the C++ compiler team went to great lengths to make sure that all of the expertise gained from years of optimizing native code was applied to managed code optimization. C++ gives you the flexibility to do fine tuning such as high-performance marshaling that is not possible with other languages. Moreover, the Visual C++ compiler generates the best optimized MSIL of any of the .NET languages. The result is that the best optimized code in .NET comes from the Visual C++ compiler.
|
|
|
|
|
I am new to C#. I have written a class library in C# that has a form. I want this form to return some value when it terminates. This form is called from some other project.
Lets assume I have a text box [text1] and a button [button1] on the form. When the form loads, user will provide some text in text1 and on clicking button1 the form will terminate and text will be returned.
I want to pass a variable ref to its [form's] constructor, then assign the this reference to some static ref variable so that it could be changed in button1's click event.
In short, I want to modify a constructor's ref parameter in an event procedure.
Thanks in advance,
Vipin.
|
|
|
|
|