|
Use tabs '\t' or fill the gaps with spaces and use a monospace font like Lucida Console or Courier New
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks,
But i need to format the string in different way.
The '\t' give me 4 spaces only and cant help me to save the same format.
I looking for some format that can save me the state of the line.
|
|
|
|
|
Spaces + Monospace Font, as I said.
This of course depends on the font the viewer of the data uses, but there's no other way than to use the same string length via spaces and then force the viewer program to use a monospace font.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
a ListBox is more suited to show independent lines of text:
- it never needs the concatenation of all text lines
- it knows how to store a collection of objects, not just strings
- it allows for user drawing.
Without user drawing, you would have to choose a non-proportional (=monospace) font
and insert spaces and/or tabs to align columns.
With user drawing (set DrawMode to DrawMode.OwnerDrawFixed), you can draw each line
yourself. If you have stored a small struct (say string col1, string col2), you can
now paint the different columns individually, using whatever color, size, etc you choose.
|
|
|
|
|
Hi.
I'm trying to connect to SQL Server Express using a DSN. The DSN and SSE is set up with Windows NT authentication. I've tried SqlConnection thisConnection = new SqlConnection("DSN=ESGAS;Integrated Security=SSPI;"); but I get an error saying 'dsn' is not a recognised keyword.
Thanks in advance.
The FoZ
|
|
|
|
|
Don't worry I think I've solved it. It seems that the SqlConnection uses its own protocol to connect to the SQL Server as per this[^] article on MSDN.
The FoZ
|
|
|
|
|
Hi,
I'm using a outlook 2007 add-in project. In this project I added a reference to a dll. Somehow I can't make any calls to any of the methods in that dll. I keep getting FileLoadException. I have strong named this assembly. I read in one place that I have to grant trust to that assembly. Any idea how to fix this? After adding strong name I get this error:
A first chance exception of type 'System.IO.FileLoadException' occurred in MyClass.DLL
Could not load file or assembly 'MyClass, Version=1.0.3094.41526, Culture=neutral, PublicKeyToken=52388ff89a43b4bd' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)
Thanks
Ben
|
|
|
|
|
Hi All,
I've not used reflection before so this is all really new to me. I have an object that I want to build in some automating dynamic behaviour based on what 'called it'. What's the best way to get the Type name of the calling type in this objects constructor?
Cheers,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
You could pass it to the constructor for the new object and then use the System.Object.GetType() method to get it's type (of the object that constructed it) and do further processing from there.
There's a bunch of different ways. And it depends on how many "calling" objects you're dealing with.
|
|
|
|
|
Thanks Bert,
It does make more sense to pass it in and then build some form of switch statement I guess.
Thanks,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
You can look at the collection of StackFrame objects returned by System.Diagnostics.StackTrace. The first frame should be your constructor, and the second the method that called it.
|
|
|
|
|
Ahhhhh!! Thanks chap!
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Unfortunately this does not work in all cases and is not guaranteed to work in future versions of the framework. See Mike Stall's blog [^]for more info.
The question one should be asking is "why does the constructor need to know the declaring type of its calling method?"
|
|
|
|
|
Thanks, I didn't know that. Ya, if the question is unavoidable, I suppose passing the result of this.GetType() to the constructor is nice and clear about what is going on.
|
|
|
|
|
Hi everybody.
Is it allowed to mix lock and Monitor.TryEnter commands on the same locking object? I think that lock is implemented using Monitor.Enter and Monitor.Exit - so there should be no problems. Am I correct?
Thanks
Uros
|
|
|
|
|
Yes, lock is expanded by the compiler to Monitor.Enter /Monitor.Exit , so
lock (obj)
{
} gets expanded to
Monitor.Enter(obj);
try
{
}
finally
{
Monitor.Exit(obj);
} I'm not sure how you would mix the Monitor.TryEnter with using a lock on the same object since you would then be acquiring two locks on the same object.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines][ Articles][ Blog]
|
|
|
|
|
Thanks for your reply! I'm am not using lock all the time becouse I need the time out functionality of the Monitor.TryEnter. I hade in mind something like that:
private void doSomething()
{
lock(_locker)
{
//Do something here
}
}
private void doSomethingElse()
{
bool lockAquired = Monitor.TryEnter(_locker, 100)
if(lockAquired)
{
//Do something else
Monitor.Exit(_locker);
}
}
Is that OK?.
|
|
|
|
|
That should be fine. The only thing you should change in your doSomethingElse method is that it should be wrapped in a try/finally block like this:
private void doSomethingElse()
{
bool lockAquired = Monitor.TryEnter(_locker, 100);
try
{
if(lockAquired)
{
}
}
finally
{
Monitor.Exit(_locker);
}
} This way, if something fails and throws an exception while you have the lock acquired, you will be sure to release it and minimize the chance of a deadlock condition.
You might also want to take a look at the following blog post from Ian Griffiths: http://www.interact-sw.co.uk/iangblog/2004/04/26/yetmoretimedlocking[^] (the site appears to be down at the moment, but it should be back up soon, hopefully.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines][ Articles][ Blog]
|
|
|
|
|
I'll do that. Thanks again for all your help.
Uros
|
|
|
|
|
I wrote some class that inherit from the class TextBox - and i try to override the method OnKeyPress.
What i try to do is make the control valid only for digit.
So I check the argument that my method gets and live the text as it was before OnKeyPress call in case the argument is not digit.
I see actualy that even the fact that my OnKeyPress calls - the char that is not digit gets into the contol.
The code :
protected override void OnKeyPress(KeyPressEventArgs e)
{
string strBefore = Text;
if (char.IsDigit(e.KeyChar))
{
....
}
}
p.s - i also override the method OnkeyUP and OnkeyDown - and nothing helps.
|
|
|
|
|
Hi,
the Control will continue to process its inputs in the normal way, unless you set e.Handled=true;
|
|
|
|
|
The code :
protected override void OnKeyPress(KeyPressEventArgs e)
{
string strBefore = Text;
if (char.IsDigit(e.KeyChar))
{
....
}
}
I'm not sure... But try It out.....My compiler is not working.....
Try Using This code :
protected override void OnKeyPress(KeyPressEventArgs e)
{
string strBefore = Text;
if (char.IsDigit(e.KeyInt))
{
// The char Data Type gives u the problem or error
// The int data type has to give only the digit as input....
}
}
|
|
|
|
|
PRAVEEN@IT2008 wrote: I'm not sure... But try It out.....My compiler is not working...
If you don't have access to a compiler, you should at least take a look at the documentation intead of just guessing wildly...
There is no KeyInt property in the class.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I have the following code. I've install the service, and start it. I want to create a file 'c:\test.txt' using the timer. But the file still can't be created. I've check for Application error at windows 'event viewer', but have not find any.
using System;
using System.Diagnostics;
using System.ServiceProcess;
using System.IO;
namespace WindowsService
{
class WindowsService : ServiceBase
{
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
public WindowsService()
{
this.ServiceName = "G-ERP Auto backup";
this.EventLog.Source = "G-ERP Auto backup";
this.EventLog.Log = "Application";
this.CanHandlePowerEvent = true;
this.CanHandleSessionChangeEvent = true;
this.CanPauseAndContinue = true;
this.CanShutdown = true;
this.CanStop = true;
InitializeComponent();
if (!EventLog.SourceExists("G-ERP Auto backup"))
EventLog.CreateEventSource("G-ERP Auto backup", "Application");
}
static void Main()
{
ServiceBase.Run(new WindowsService());
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
protected override void OnStart(string[] args)
{
this.timer1.Enabled = true;
base.OnStart(args);
}
protected override void OnStop()
{
this.timer1.Enabled = false;
base.OnStop();
}
protected override void OnPause()
{
this.timer1.Enabled = false;
base.OnPause();
}
protected override void OnContinue()
{
this.timer1.Enabled = true;
base.OnContinue();
}
protected override void OnShutdown()
{
base.OnShutdown();
}
protected override void OnCustomCommand(int command)
{
base.OnCustomCommand(command);
}
protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
{
return base.OnPowerEvent(powerStatus);
}
protected override void OnSessionChange(SessionChangeDescription changeDescription)
{
base.OnSessionChange(changeDescription);
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
}
private void timer1_Tick(object sender, EventArgs e)
{
File.Copy(@"c:\YServer.txt", @"c:\test.txt");
if (!File.Exists(@"c:\YServer.txt"))
{
File.Copy(@"c:\YServer.txt", @"c:\test.txt");
}
}
}
}
|
|
|
|
|
Yulianto. wrote:
File.Copy(@"c:\YServer.txt", @"c:\test.txt");
if (!File.Exists(@"c:\YServer.txt"))
{
File.Copy(@"c:\YServer.txt", @"c:\test.txt");
}
File.Copy(@"c:\YServer.txt", @"c:\test.txt");
if (!File.Exists(@"c:\YServer.txt"))
{
File.Copy(@"c:\test.txt",@"c:\YServer.txt");
}
Check the difference on the bold line
Bob
Ashfield Consultants Ltd
|
|
|
|