|
Hi,
I'm outputting some logging output to a TextBox, using the following code:
public void AddNewMessage( String message )
{
lock (this)
{
if (disposed)
throw new ObjectDisposedException( "PeerMessagesDisplay" );
String text = this.textBox1.Text.Insert( this.textBox1.Text.Length, message );
SetText( text );
}
}
private void SetText( String text )
{
if (this.InvokeRequired)
this.textBox1.Invoke( new Action<string>( SetTextHelper ), text );
else
SetTextHelper( text );
}
private void SetTextHelper( String text )
{
this.textBox1.Text = text;
}
</string>
But, whenever text is appended to the textbox, it automatically scrolls up to the top. This is bad when I'm trying to observe the output at the bottom or somewhere in the middle. How can I maintain the textbox's scroll position?
Thanks,
klk
madness ? this.isSparta = true : this.isSparta = false;
|
|
|
|
|
Use the AppendText method on the TextBox. I think that maintains the scroll position.
"An eye for an eye only ends up making the whole world blind"
|
|
|
|
|
Hey Rob,
This is a better solution, you are right. Unfortunately, it still always keeps the textbox's scroll position locked at the bottom. Is there a way around that?
klk
madness ? this.isSparta = true : this.isSparta = false;
|
|
|
|
|
Hi klk, I tried a couple of things here to try & get this working! Simplest solution is to use the SelectionStart property, although this is still not ideal... Try this:
Dim i As Integer = TextBox1.SelectionStart
Dim atEnd As Boolean = i >= TextBox1.Text.Length
TextBox1.AppendText("New line: " + TextBox1.Text.Length.ToString() + vbNewLine)
If Not atEnd Then
TextBox1.SelectionStart = i
TextBox1.ScrollToCaret()
End If
Other than this, you could look at using the native scroll functions (GetScrollInfo, SetScrollInfo) - see google & msdn for more info about these.
Hope this helps! Rob
"An eye for an eye only ends up making the whole world blind"
|
|
|
|
|
Hey Rob,
I tried that solution, but the SelectionStart property refers to where the cursor is, not the scrollbar. Basically, unless the user clicks inside the textbox to place the cursor somewhere, it doesn't work.
I looked up the P/Invoke stuff for Get/SetScrollInfo, but that's not working either! It still always jumps down to the bottom of the textbox. Here's my refactored code:
public partial class PeerMessagesDisplay : Form
{
#region ScrollInfo
[DllImport( "user32.dll" )]
[return: MarshalAs( UnmanagedType.Bool )]
private static extern bool GetScrollInfo( IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi );
[DllImport( "user32.dll" )]
static extern int SetScrollInfo( IntPtr hwnd, int fnBar, [In] ref SCROLLINFO
lpsi, bool fRedraw );
[StructLayout( LayoutKind.Sequential )]
struct SCROLLINFO
{
public uint cbSize;
public uint fMask;
public int nMin;
public int nMax;
public uint nPage;
public int nPos;
public int nTrackPos;
}
private enum ScrollBarDirection
{
SB_HORZ = 0,
SB_VERT = 1,
SB_CTL = 2,
SB_BOTH = 3
}
private enum ScrollInfoMask
{
SIF_RANGE = 0x1,
SIF_PAGE = 0x2,
SIF_POS = 0x4,
SIF_DISABLENOSCROLL = 0x8,
SIF_TRACKPOS = 0x10,
SIF_ALL = SIF_RANGE + SIF_PAGE + SIF_POS + SIF_TRACKPOS
}
#endregion
private String title;
private String logFile;
private bool disposed;
public PeerMessagesDisplay( String title, String logFilePath )
{
InitializeComponent();
this.title = title;
this.logFile = logFilePath;
this.Show();
}
public void LoadLog( )
{
ThreadPool.QueueUserWorkItem( delegate
{
try
{
if (this.InvokeRequired)
this.BeginInvoke( new Action<string>( delegate( String s ) { this.Text = s; } ), title );
else
this.Text = title;
using (FileStream fs = File.OpenRead( this.logFile ))
{
using (StreamReader reader = new StreamReader( fs ))
{
String text = reader.ReadToEnd();
AddNewMessage( text );
}
}
}
catch (IOException ioe)
{
AddNewMessage( ioe.Message );
}
} );
}
public void AddNewMessage( String message )
{
lock (this)
{
if (this.textBox1.InvokeRequired)
this.textBox1.BeginInvoke( new Action<string>( AddNewMessageInvoke ), message );
else
AddNewMessageInvoke( message );
}
}
private void AddNewMessageInvoke( String message )
{
SCROLLINFO scrollInfo = new SCROLLINFO();
GetScrollInfo( this.textBox1.Handle, (int)ScrollBarDirection.SB_VERT, ref scrollInfo );
this.textBox1.AppendText( message );
SetScrollInfo( this.textBox1.Handle, (int)ScrollBarDirection.SB_VERT, ref scrollInfo, true );
}
}
}
</string></string>
madness ? this.isSparta = true : this.isSparta = false;
|
|
|
|
|
Hi, you need to set the cbSize and fMask fields before calling GetScrollInfo. Try using:
scrollInfo.cbSize = Marshal.SizeOf(SCROLLINFO);
scrollInfo.fMask = ScrollInfoMask.SIF_POS;
I think this should work, but havn't tried it...
Rob
"An eye for an eye only ends up making the whole world blind"
|
|
|
|
|
Hi,
for displaying log information I prefer a ListBox over a TextBox.
For one, it is much faster, since it keeps all the text lines apart, it never needs
them all concatenated.
Furthermore, it has a TopIndex property, which determines the scroll state.
So a typical log method would consist of:
void log(string s) {
lb.Items.Add(s);
lb.TopIndex=lb.Items.Count-1;
}
|
|
|
|
|
Thanks luc, this worked perfectly.
madness ? this.isSparta = true : this.isSparta = false;
|
|
|
|
|
You're welcome.
|
|
|
|
|
|
I have an article on per pixel collision detection here on CP. My solution is not very fast tho, it probably needs to be reconsidered.
The simplest thing to do is to work out the smallest square each shape occupies and work out if any squares intersect. How well that works, depends on your polygons.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks a lot! I am going to read your article!
|
|
|
|
|
I am trying add databinding to one of my textbox. When I click on "Text" under "DataBindings" section in the property grid, I get an error says "Object reference not set". Any idea to solve this ? I have tested it with another project and it works correctly. Any ideas ?
|
|
|
|
|
Hi,
There are several reasons which can cause this error, few of them are:
1) Some classes have constructors; therefore you need to properly instantiate it.
2) Bad scoping.
3) MAKE SURE that you've explicitly declared the variable, and don't forget to use the appropriate scope.
Since you are not getting the same error in another project therefore, I try to match the property settings of both project and manipulate them to see if this helps.
Hope this helps.
Have a nice day.
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
I know when this error occurs and I could have corrected it if it was my code. But this is happening with VS2005. As you said, some properties will be invalid. Thanks anyway
|
|
|
|
|
Hi all,
Currently i am using the autoscroll properties to enable scrollbar, but it will enable both of the vertical and horizontal scrollbar.So, i would like to know how can i enable only vertical scrollbar in panel?
regards
cocoonwls
|
|
|
|
|
Hi,
Please take to through the following article.
http://www.codeproject.com/KB/miscctrl/CustomAutoScrollPanel.aspx[^]
This article show how to customize a System.Windows.Forms.Panel to use effectively scrollbars with the AutoScroll property. In this example, you can change enable or visible property of each scrollbar of the panel, receive scrolling events, send events to the panel and change and receive the positions of both scrollbars.
Hope this helps
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
I'm strucking with this form last 3 weeks ,and i'm working on windows Project,
my project setup (the user has no .net frame work ,sql server etc..,we have to put exe files along with our project ,How can I do this,I'm sending my steup fail Error details also) , and we are using C# 2008 Express Edition,
if u know this please,please help me.
--------------------------------------------------------------------
erro Details:
Error: 1 Cannot publish because a project failed to build. 1 1 setuptesting
Error 2: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'WindowsInstaller3_1\WindowsInstaller-KB893803-v2-x86.exe' in item 'Windows Installer 3.1' can not be located on disk. See Help for more information. setuptesting
Error 3 : The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\aspnet.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 4: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\aspnet_64.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 5: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\clr.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 6: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\clr_64.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 7: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\crt.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 8: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\crt_64.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 9: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\dw.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 10: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\dw_64.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 11: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\netfx20a_x64.msi' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 12: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\netfx20a_x86.msi' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 13: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\netfx_ca.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 14: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\netfx_core.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 15: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\netfx_core_64.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 16: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\netfx_other.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 17: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\netfx_other_64.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 18: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\prexp.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 19: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\winforms.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 20: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX20\winforms_64.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 21: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\x86\msxml6.msi' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 22: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\x64\msxml6.msi' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 23: The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\NetFX30a_x64.msi' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 24 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\NetFX30a_x86.msi' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 25 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\RGB9RAST_x64.msi' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 26 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\RGB9RAST_x86.msi' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 27 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WCF.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 28 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WCF_64.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 29 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WCS.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 30 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WCS_64.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 31 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WF.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 32 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WF_32.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 33 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WF_64.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 34 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WIC_x64_enu.exe' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 35 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WIC_x86_enu.exe' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 36 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WPF1.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 37 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WPF1_64.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 38 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WPF2.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 39 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WPF2_32.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 40 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WPF2_64.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 41 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WPF_Other.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 42 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WPF_Other_32.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 43 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\WPF_Other_64.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 44 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\XPS.msp' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 45 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\XPSEPSC-x86-en-US.exe' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 46 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX30\XPSEPSC-amd64-en-US.exe' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 47 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX35\x86\netfx35_x86.exe' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 48 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFX35\x64\netfx35_x64.exe' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 49 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetMSP\x86\NetFX2.0-KB110806-v6000-x86.msu' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 50 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetMSP\x86\NetFX2.0-KB936704-v6000-x86_RTM_en.msu' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 51 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetMSP\x86\NetFX3.0-KB929300-v6000-x86.msu' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 52 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetMSP\x86\NetFX3.0-KB936705-v6000-x86_RTM_en.msu' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 53 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetMSP\x64\NetFX2.0-KB110806-v6000-x64.msu' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 54 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetMSP\x64\NetFX2.0-KB936704-v6000-x64_RTM_en.msu' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 55 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetMSP\x64\NetFX3.0-KB929300-v6000-x64.msu' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 56 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetMSP\x64\NetFX3.0-KB936705-v6000-x64_RTM_en.msu' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 57 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX35\dotNetFx35setup.exe' in item '.NET Framework 3.5' can not be located on disk. See Help for more information. setuptesting
Error 58 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'SqlExpress\sqlexpr32.exe' in item 'SQL Server 2005 Express Edition SP2 (x86)' can not be located on disk. See Help for more information. setuptesting
|
|
|
|
|
Try creating a new setup project because the SDK seems not to be included....
Best Regards,
Sam Xavier
www.componentone.com
|
|
|
|
|
Dear All,
In My project one of the task is to read Outlook mail saved in localfolder.let say as it saved as " C:\\Test.EML " . I need to upload this mail display it in any manner.
i have tried the same with web application using C# with ASPOSE.DLL ,but the same thing is not Working in Windows application.
Please give me some suggestions or idea to open this email from local disk.
Thanks and Regards
Shalu
|
|
|
|
|
I had used UltraColorPicker control to show the color in a column in listview. But while selecting the color it is showing some relevant numbers instead of color name for few colours in Custom tab. Did i miss any settings here..... ? Any one help me....
Thanks in advance
|
|
|
|
|
What is ultracolorpicker ? I have no idea. I'm sure many others do not either. So, how can we help you ? Do the ultracolorpicker people not have a website ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi..
I Need to Draw a sine wave on the Form, based on the X and Y values. I have stored those values in List variable..
How can i draw a continuous sine wave using GDI+ using C#
|
|
|
|
|
Best bet is probably Graphics.DrawLines to draw straight-line segments between the points.
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|