-
Controls Size property
Date: 09/21/05
Keywords: no keywords
Hi guys,
here is another freaky thing that kind of bugs a lot. Maybe someone has ideas to this. We have a sort of a "dynamic" interface builder that will take a control schema and place the controls into a TableLayoutPanel control with pre-created rows and columns. All row and columns styles are set to AutorSize SizeType.
What happens is even though the TableLayoutPanel AutoSize property is set to true and its AutoSizeMode to GrowAndShrink, it will not grow enough to show the full control inside a cell.
The whole thing looks bit messy: a Panel with a couple of cells with TabbedControl, then TableLayoutPanel inside of it with a few GroupBox controls that will contain TableLayoutPanels as well.
What I tried to do is this bit of code:
protected void setSize(Control ctrl)
{
if (!ctrl.Created)
{
ctrl.CreateControl();
}
foreach(Control cc in ctrl.Controls)
{
if (!cc.Created)
{
cc.CreateControl();
}
if (cc.Controls.Count > 0)
{
cc.AutoSize = false;
cc.Size = cc.PreferredSize;
}
setSize(cc);
}
}
A simple recursion that will run through all the controls all try to set their Size property to equal PrefferedSize property.
The funny thing, again, is that once this is executed:
cc.Size = cc.PreferredSize;
the Size will not change to equal the PrefferedSize property.
How can this be possible? Can it be something like the parent control sort of "holding" the children size and change it back once it was changed somewhere?
Please advide, I am about to run into a wall and nock myself out.
Source: http://www.livejournal.com/community/csharp/35393.html
-
System.Diagnostics.Trace
Date: 09/20/05
Keywords: no keywords
When using System.Diagnostics.Trace to well...trace, what is the best way to make sure that TextWriterTraceListeners get closed? I saw in a few examples that you can call Trace.Close(), but then it seems like you'd have to either use a finalizer or else re-open and then close the Trace each time you needed it.
The reason I ask is because I'm using trace to a little bit of simple logging to a flatfile, and I can only seem to use the flatfile once, because the next time I try to open it, it fails because the file is in use by another process. Any general tips\best practices when using Trace would be appreciated.
Source: http://www.livejournal.com/community/csharp/35290.html
-
Is there a C# equivalent to C's "typedef"?
Date: 09/16/05
Keywords: no keywords
I'm finding that with the addition of generics that I'm getting some very long type names, which not only are verbose but obscure the meaning of what I'm writing. I'd like to give a meainingful name to complicated data types, but I can't see a C# equivalent of typedef. Is there an easy way to do it? (Just writing an empty class that inherits the type I want won't do it; too much of the CLR is sealed).
Am I missing something?
Source: http://www.livejournal.com/community/csharp/34842.html
-
Transparent Panel (C#, .net 2.0)
Date: 09/07/05
Keywords: google
Hi all,
while trying to organize a transparent panel for one of the controls, faced another problem with Windows Forms Controls - can't make it transparent.
I found a way around it (thank Google) to ovveride these two:
protected override void OnPaint(PaintEventArgs e)
{
//
}
protected override CreateParams CreateParams
{
get {
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
}
}
It sort of help, but there are two issues with this:
there is still a part of the panel that is NOT transparent (over one of the controls) and when the Panel is resized etc, it horribly blinks.
Is there another way to organize proper transparency for Panel?
Source: http://www.livejournal.com/community/csharp/34775.html
-
VS.NET on Windows x64
Date: 09/06/05
Keywords: no keywords
Anyone do C# development in Visual Studio .NET on Windows x64? Any gotchas or anything I should know before I try to use my new Opteron box for Windows development?
Source: http://www.livejournal.com/community/csharp/34526.html
-
Weirdest problem with Windows forms control.
Date: 09/05/05
Keywords: no keywords
Hi guys,
I have faced this weirdest problem with C#.NET 2.0 (Windows Forms).
I have a class that creates an instance of a (Control) Slider() and passes an instance of CheckedListBox() to it. I set the size of CheckedListBox() to (160,100).
The Slider() it its constructor adds the CheckedListBox() that was passed to it to its Contols collection (this.Controls.Add(PassedControl);)
Then I add the Slider() to the form as well.
It looks something like this:
class a
{
using ...;
pulic a()
{
CheckedListBox box = new CheckedListBox();
box.Size = new Size(160,100);
myPanel x = new myPanel(box);
Contols.Add(x);
}
}
Where the myPanel looks something like this:
Class myPanel : System.Windows.Forms.Panel{
protected Control inner;
public myPanel(Contol _ctrl){
inner = _ctrl;
this.Controls.Add(inner);
}
}
My problem is that once the CheckedListBox() is added to the panel, it will change its size a bit. I guess .NET does this to actually make its size be x*Item.Height; so that it looks good or something.
Now, somewhere in the constructor for the myPanel I am trying to get the actual size of the CheckedListBox() and here the weird part starts.
It will always return 100. But the real size of it is 85.
The way I figured this out is this - add "int x = inner.size.height;" and then put a break right after this line.
You will see the both the x and inner.size.height are 100;
now - add the inner to quick watch and it will somehow recalculate the size and the inner.size.height will become 85 but x will remain 100.
Am I missing something or gone mad or what? But when I run this it will not return its real size unless I do the trick with quick watch for "inner". Both the inner.ClientSize and inner.Bounds return same 100 unless "quick watched".
I tried tricks with ResumeLayout() and PerformLayout() and Refresh() and Invalidate() - these don't seem to be helping a lot.
Any ideas, this really is killing me now?
And thanks a lot.
Source: http://www.livejournal.com/community/csharp/34128.html
-
Active Directory and .NET
Date: 08/31/05
Keywords: database, asp, web
Hi everybody!
I have a question about Active Directory in .NET
For my project I need to fetch results from Active Directory search page by page, because later I would need to bind it to the pageable DataGrid.
I tried to use .NET library DirectoryServices for that, but paging provided by this library is transparent to the user and is used only to increase the efficiency of searching, when results are too big. I.e. I cannot tell the DirectorySearcher to give me first page, then the next or previous page, it returns me all resulting pages in one bundle.
However, what I need is to explicitely get page after page directly from the AD searcher and to be able to go at least one page forward or backward.
The solution with copying all results to the DataBase and then do the paging is not accepeted by the clent, since it is too inefficient. And since it's a Web app, I cannot keep results in memory either.
I found some hints about COM Interface, but I could not find good and detailed examples or explanations.
If somebody could help me out with that problem, any suggestion is welcome, 'cause this issue is eating me alive :)
Thank you!
x-posted in asp_net
Source: http://www.livejournal.com/community/csharp/33805.html
-
Re: UserControl output into an XmlNode
Date: 08/16/05
Keywords: html, xml
A continuation of my awkward question for any C# geeks reading.
Ok, I don'think I'm gonna find a convenient way to do it the way I'd hoped, so I've started thinking about rendering the control into a Stream and XmlDocument.Load-ing that Stream into my XmlNode hierarchy.
Except I'm not getting anything out using Control.RenderControl(HtmlTextWriter):
public XmlDocument RenderXmlDocument()
{
MemoryStream stream = new MemoryStream();
this.RenderControl(new HtmlTextWriter(new StreamWriter(stream)));
byte[] streamContents = stream.ToArray();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (byte tmp in streamContents)
sb.Append(Convert.ToChar(tmp));
HttpContext.Current.Trace.Write("EditSectionOrAsset",
"Rendered control as \n\n[" + sb.ToString() + "]");
XmlDocument control = new XmlDocument();
control.Load(new XmlTextReader(new StreamReader(stream)));
return control;
}
and nothing is getting written to the Trace.
Am I gonna have to work out how to do this without using the control?
Any and all suggestions gratefully received. Cross-posted to owenblacker, csharp and ms_dot_net.
Source: http://www.livejournal.com/community/csharp/33333.html
-
UserControl output into an XmlNode
Date: 08/15/05
Keywords: cms, html, xml
Very cheeky of me, having only just joined this community, but may I post an awkward question?
In a CMS-like environment, I have a list of items that is generated on the serverside using an XmlDocument to throw together XHTML tags (mainly because it's substantially easier than using a Repeater, but the why is a moot point as the project doesn't have the budget for me to change that).
Now I have a requirement to add a new list item at the end of each list that is an "Add new item" form. It's very easy for me to write a UserControl to handle this form action, but would be relatively difficult to write this form bit as XmlElements to add into the exsiting XmlNode tree.
Is there a way for me to get the output of the server control as an XmlNode and squish that into my XmlNode tree?
Effectively, I want to take my existing code and making it look something like this:
bool isInAuthoringMode;
XmlDocument xml;
XmlElement div;
5 // ...
if (isInAuthoringMode || (this.Assets != null &&
this.Assets.Count > 0)
{
10 XmlElement ul = xml.CreateElement("ul");
ul.Attributes.Append(xml.CreateAttribute("class"));
ul.Attributes["class"].Value = "file-list";
foreach (Asset a in this.Assets)
15 ul.AppendChild(a.ToXml(xml));
if (isInAuthoringMode)
ul.AppendChild(new EditControl().ToXml(xml));
20 div.AppendChild(ul);
}
Line 18 in this code block is what I'd really like to be able to do, but I know that would be being very optimistic.
Is there any obvious way of getting "the HTML this control would generate here" out of it, even if I have to write a new method into it somewhere?
The behavior I seek is roughly the same as if I had a Repeater like this:
But I can't use a Repeater (for reasons too tedious to detail here).
Any ideas gratefully received. Thanks!
Cross-posted to owenblacker, csharp and ms_dot_net. Sorry :o)
Source: http://www.livejournal.com/community/csharp/33259.html
-
hmm
Date: 08/12/05
Keywords: asp, sql, microsoft
gotta love it when you research a weird error you're getting and microsoft says this.
SYMPTOMS
When you use the Microsoft Visual Studio .NET debugger to debug an ActiveX Data Objects (ADO) application that contains Transact-SQL code, you may receive the following error message:
System.Data.SqlClient.SqlException: General network error. Check your network documentation.
You may notice this behavior when you restart Microsoft SQL Server while debugging the ADO application.
Back to the top Back to the top
STATUS
This behavior is by design.
...
BY DESIGN?
ok, microsoft. you win today. :|
anyways, on a related but not so related note.. our middle tier component that handles data connections started giving us the infamous "General network error. Check your network documentation." upon an executenonquery call on a stored procedure after we applied service pack 4 on SQL Server. anyone know why oh why SP4 is doing this?
please enlighten while i sniff out the chatter on the .NET boards.
xposted to sqlserver and aspdotnet
Source: http://www.livejournal.com/community/csharp/32809.html
-
SetWindowsHookEx() in a Windows Service?
Date: 08/11/05
Keywords: programming, software, xml, security, web, google
Hello all. First time posting -- I'm an executive/part owner of a small, 30-40 employee software development company in the US. Can't get any more specific, due to LJ drama that occurred in the past, from which I learned that my constant insistence upon plausible deniability is never a bad thing.
Anyway, all of our current contracts are in .NET, from winforms applications, to windows services, to webservices, to web applications. We write in C#.NET and VB.NET depending on the contract, application, and developer. We've been working with .NET for the past 2-3 years.
I don't do as much programming with my company as I did when I first started there as Lead Developer; a good deal of my responsibilities have changed to software design/architecture, scheduling, project management, and having my time wasted by as many meetings as possible, at the most inconvenient times.
So perhaps these latest developments will lend an excuse to the following ignorance. :)
I am writing an application for myself, completely unrelated to my company, in my "free time." It has a fairly eccentric variety of functionality, all of which is related in a certain way, but the functionality with which this post concerns itself is keypress logging.
I've written a class that uses the SetWindowsHookEx() WinAPI call to install a hook for keyboard events (using WH_KEYBOARD_LL). It sets up the hook, which simply raises an event (passing the keypress data along) before giving the keypress back to the system (which continues down the chain of installed hooks). I've written a parent class which attaches a method to the event that takes the useful information from the keypress data and stores it in a queue. The remainder of this parent class provides access to the queue, functionality to clear it, etc. The class that implements SetWindowsHookEx() is in a DLL (I wrote it as part of a separate application back when I was more comfortable with VB.NET, while the current project is in C#, thus the DLL), and the parent class (in C#) imports this DLL.
The class performs flawlessly in the Windows Forms application I wrote to test all of the classes destined to be part of the final solution. It properly logs all of the keypresses in its queue, its methods provide the proper access to the queue, and the test application could write the keypresses to a file, store them in an XML object, or whatever needed to happen. I was pleased, since the whole mess only took about 2 hours to develop and test.
However, the final application that will be doing the keylogging is a Windows Service. Now that I finished developing and testing all the classes I needed to use in the final application, I've begun building the service. I've got the service properly installing, starting, and logging to the system's event log, so I know the service itself is working. However, the keylogging class is not working. No exceptions are thrown, and the WinAPI call (from user32.dll) returns no error codes. However, the queue count remains at 0, and no keys are logged at all.
I've simply dragged the class from the test Winforms application into the Windows Service application, and used it in the same way. While keypresses were logged efforltessly in the Winforms application, not a single one is being logged in the Windows Service.
I have tried pretty much everything I can think of, from checking the "Allow this service to interact with the desktop" checkbox, to changing the account running the service (currently the Local System account). However, as I said above, programming is not a day-to-day thing for me anymore, so I am most likely ignorant of something here.
I've read many accounts via Google of people successfully using SetWindowsHookEx() in a Windows Service, so I know it can be done. What gives? Is this a permissions/security issue, and if so, why are no errors/exceptions being thrown? Do I need to register the DLL containing the class that calls SetWindowsHookEx() in the GAC for any reason?
Any information or help will be greatly appreciated. Thanks in advance...!
Source: http://www.livejournal.com/community/csharp/32613.html
-
Phat C# Database Tool
Date: 08/02/05
Keywords: mysql, sql
I am nearly done with a DB Tool for C# and MySQL. Please See My Entry for more details...
Source: http://www.livejournal.com/community/csharp/32384.html
-
CR/LF
Date: 07/26/05
Keywords: no keywords
Has anyone here ever implemented the IMAP protocol?
I'm stuck on the APPEND command. I think I'm setting it all up correctly, but no matter what I do, I get the response that the command must be terminated with a CR/LF combination. I send "\r\n" at the end of the command, and aside from that, I'm not sure what else I can do.
In general, if you had to send a CR/LF over a telnet connection, how would you do it?
Source: http://www.livejournal.com/community/csharp/32016.html
-
ActiveX, PowerPoint, C#
Date: 07/05/05
Keywords: no keywords
Hi, I'm want to create a windows control in C# and expose it as an ActiveX control to be used in PowerPoint. Has anyone attempted this before with C# or has suggestions? Thanks!
Source: http://www.livejournal.com/community/csharp/31758.html
-
The frustration of unit test
Date: 06/27/05
Keywords: google
I like unit tests. It's cool to be able to try out little bits of your code, and make sure the small parts work before you try making it do larger things. It's good stuff.
But by god - does it have to be so poorly documented?
In this case I'm looking at NUnit.Util. This is part of the standard NUnit install, and it contains a bunch of classes - and no documentation on them. I've done searches through google - no documentation found.
Does this stuff get used?
What I needed: A way to trap output that is supposed to go to the console so I can make sure that something that writes to it is actually writing what I wanted.
What I eventually did: I took the NUnit.Util.ConsoleWriter, and inherited from it as below. Then, I passed it in as a TextWriter, which my console app would write to.
using System;
using System.Text;
using System.IO;
using NUnit.Util;
namespace moCSCXIImport.Tests
{
///
/// Summary description for MockConsole.
///
public class MockConsole : ConsoleWriter
{
private StringBuilder TextBuffer;
public MockConsole(TextWriter console) : base(console)
{
TextBuffer = new StringBuilder();
}
public override void Write(char c)
{
TextBuffer.Append(c);
base.Write(c);
}
public override void Write(String s)
{
TextBuffer.Append(s);
base.Write(s);
}
public override void WriteLine(string s)
{
TextBuffer.Append(s);
TextBuffer.Append("\n"); // newline
base.WriteLine(s);
}
public string TextWritten
{
get { return TextBuffer.ToString(); }
}
public long GetTextLength()
{
return TextBuffer.Length;
}
}
}
But I'm sure someone's done something like this before. But why couldn't I *find* it?
Source: http://www.livejournal.com/community/csharp/31735.html
-
Рассылка .Net Собеседник
Date: 06/16/05
Keywords: asp, sql
На subscribe.ru есть рассылка - http://subscribe.ru/catalog/comp.soft.prog.dotnetgrains, у рассылки есть сайт - http://dotnetgrains.sql.ru/.
Рассылка посвящена платформе .Net, C#, ASP.Net.
На обоих сайтах размещены прежние выпуски - всего 42.
Подписывайтесь, если интересно.
Source: http://www.livejournal.com/community/csharp/31363.html
-
Question about VS extensibility and C#
Date: 06/09/05
Keywords: html, asp, microsoft
I've been trying for a while to access the linker object's mapfile setting for a project in Visual Studio .NET via the extensibility model. I'm writing in C#.
Microsoft has this to say about it:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcext/html/vxlrfvcprojectenginelibraryvclinkertoolmapfilename.asp
The example code they provide is for VB .NET, and goes something like this:
--------------
Imports EnvDTE
Imports Microsoft.VisualStudio.VCProjectEngine
Public Module Module1
Sub Test()
Dim prj As VCProject
Dim cfgs, tools As IVCCollection
Dim cfg As VCConfiguration
Dim tool As VCLinkerTool
prj = DTE.Solution.Projects.Item(1).Object
cfgs = prj.Configurations
cfg = cfgs.Item(1)
tool = cfg.Tools("VCLinkerTool")
tool.GenerateMapFile = True
tool.MapFileName = "my.map"
End Sub
End Module
--------------
I tried to adapt some of this to C#, but the compiler can't find the Microsoft.VisualStudio namespace, and it doesn't show up in the auto-complete list. Of course, none of the data types are recognized either (VCProject, IVCCollection, etc.). All other documentation I've seen leads me to this problem. Does anyone know of another way to access a project's active mapfile setting?
Source: http://www.livejournal.com/community/csharp/31119.html
-
round and round we go
Date: 06/03/05
Keywords: no keywords
an interesting thing that i noted while working on an app the other day.. i had to round up some currency to the nearest nickel and found some peculiar thing with .NET's Math.Round.. it wasn't exactly doing the same sort of arithmetic rounding that we learn as kids (with an upwards bias), where you would round up if the trailing digit is >=5 and round down if the trailing digit is <5. i ended up writing my own customized rounding function using a variant of an assymetric arithmetic rounding algorithm that rounds up to the nearest 0.05.
so, after some poking around and research, it seems like .NET is using an algorithm called Banker's rounding.. which at 5, it rounds to the nearest even number. pretty sleazy, imo. :) anyway, point being, if you're working on some currency related app, you may want to note the subtle yet possibly drastic possible arithmetic inaccuracy ala. the movie "office space" if you're not privy to the type of rounding algorithm a particular language is using.
here's a good article if you're interested in looking into the types of rounding algos. available and used.
http://support.microsoft.com/?kbid=196652
xposted in my journal and aspdotnet
Source: http://www.livejournal.com/community/csharp/30793.html
-
Update to Previous Post
Date: 06/02/05
Keywords: no keywords
I wanted to thank everyone that responded to my post. We've found someone to take on the project. You all are great!
Source: http://www.livejournal.com/community/csharp/30491.html
-
C# Programmer Needed
Date: 06/01/05
Keywords: web, hosting, shopping
We're a web design/hosting company. We were hired last week by a company to host their site. The site is a combination shopping cart/image vault/ FTP Product Push, etc. We were told the site was complete and ready to go live. The company that built the site was dismissed because of disagreements of some nature.
We're not proficient in C# but didn't think it would be a problem since the site was supposedly complete. The image vault portion of the site isn't working. We are supposed to go live with this on Friday, and unfortunately every C# programmer we've contacted has bailed for one reason or another.
Would anyone in this community be interested in some freelance work on a very short deadline?
Thanks in advance.
Source: http://www.livejournal.com/community/csharp/30296.html