|
hi, heath, thanx for bearing with me
no this is not a custom tab control, but a non rectangular window. the intent is for the upper poligonal(nonrectangular) part to be used as a handle to mousedrag the window by.
the first part of the code is in the contructor, and the second goes inside the OnPaint override.
im copying the code again -
in the constructor:
GraphicsPath p = new GraphicsPath();
Point[] points = { new Point(0, 0), new Point(100, 0),
new Point(150, 50), new Point(250, 50),
new Point(250, 350), new Point(0, 350) };
p.AddPolygon(points);
this.Region = new Region(p);
in the Paint override:
GraphicsPath p = new GraphicsPath();
Point[] points = { new Point(0, 0), new Point(100, 0),
new Point(150, 50), new Point(0, 50)};
p.AddPolygon(points);
g.FillPath(new SolidBrush(Color.Aqua), p);
g.DrawPath(Pens.Red, p);
if you paste this directly into a windows form application code you will see what i mean (i would have posted the entire solution if i knew how to do it here
|
|
|
|
|
You shouldn't be doing redundant calculations in your OnPaint override; you waste CPU cycles. If the GraphicsPath doesn't change, then don't keep recalculating it. OnPaint (or rather, the WM_PAINT window message) is called many, many times by the OS.
To post code, simply copy and paste the code in between <PRE></PRE> tags and escape any characters like < with <, > with >, and & with &
You also don't need VS.NET. I added csc.exe's directory (the Framework version directory) to my PATH environment variable (as well as the SDK's Bin directory) and do almost everything you'd see from me on this site using a vanilla text editor called VIM[^] and the command-line compiler.
With a VIM script, I can post this easily to this site:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class Test : Form
{
static void Main()
{
Application.Run(new Test());
}
GraphicsPath grabHandle;
Brush pathBrush = new SolidBrush(Color.Aqua);
Pen pathPen = new Pen(Color.Red);
Test()
{
GraphicsPath p = new GraphicsPath();
Point[] points = new Point[] {
new Point(0,0),
new Point(100,0),
new Point(150,50),
new Point(250,50),
new Point(250,350),
new Point(0,350)};
p.AddPolygon(points);
this.Region = new Region(p);
grabHandle = new GraphicsPath();
points = new Point[] {
new Point(0,0),
new Point(100,0),
new Point(150,50),
new Point(0,50)};
grabHandle.AddPolygon(points);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.FillPath(pathBrush, grabHandle);
g.DrawPath(pathPen, grabHandle);
}
} So far as I know, it appears to work just fine.
If you need to post a picture of what you expect, drawing something up (may I suggest the free Paint.NET[^] application from Washington University and Microsoft) and post it online. Surely you have a site somewhere where you can post a simple image. If not, you can email it to me but only as a last resort (and never continue a thread from this site personally - I get very irritated since this site contains wonderful forums). My email address you'll find in the automatic email notification message that gets sent to you when I reply to your post.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
dont worry i would bother you for something as silly as this
i've compiled your code and i got what i have achieved already:
http://viewmoresoft.com/rez1.jpg
but my goal is
http://viewmoresoft.com/rez2.jpg
i've setup the form so it is without the title bar etc
when i do a fill of the region it fills the entire visible area, but when i want to get my poligon filled it does it not the way i want.
can you see what i am trying to achieve now ?
|
|
|
|
|
In the future, please format your links to actually be links. The format toolbar below the message window is handy, and you can always use basic HTML elements when posting.
Now that I have some idea of what you want, it's quite a easy. You didn't notice that width of the angled portion was exactly the same as the width of the Windows title bar? The window frame is the non-client portion, so when you were setting your clipping area amounts where adjusted. If you set Form.FormBorderStyle to FormBorderStyle.None you'll get what you want:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class Test : Form
{
static void Main()
{
Application.Run(new Test());
}
GraphicsPath grabHandle;
Brush pathBrush = new SolidBrush(Color.Aqua);
Pen pathPen = new Pen(Color.Red);
Test()
{
FormBorderStyle = FormBorderStyle.None;
GraphicsPath p = new GraphicsPath();
Point[] points = new Point[] {
new Point(0,0),
new Point(100,0),
new Point(150,50),
new Point(250,50),
new Point(250,350),
new Point(0,350)};
p.AddPolygon(points);
this.Region = new Region(p);
grabHandle = new GraphicsPath();
points = new Point[] {
new Point(0,0),
new Point(100,0),
new Point(150,50),
new Point(0,50)};
grabHandle.AddPolygon(points);
Label lbl = new Label();
Controls.Add(lbl);
lbl.Location = new Point(8,58);
lbl.Size = new Size(200, lbl.Height);
lbl.Text = "Click anywhere to close";
lbl.Click += new EventHandler(Clicked);
}
void Clicked(object sender, EventArgs e)
{
Close();
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
Close();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.FillPath(pathBrush, grabHandle);
g.DrawPath(pathPen, grabHandle);
}
} You'll need to adjust your border line, though. Because of a behavior similar to - if not related - to culling some lines won't be visible. You could thicken your border a little and contract it a pixel or two (depending on the new thickness), or you'll need to adjust it manually based on the thickness.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
this is still not it
this is what your code and mine so far achieve. sorry, maybe i have mislead you, but in my code i do use FormBorderStyle.None, havent pointed it out, my mistake.
however what i want to achieve is this (the part in purple). do you see the difference?
i am very thankfull for your time and help.
|
|
|
|
|
It looks fine on my machine. It's only simple math, after all. You're clip is only 50 pixels down from the top and your second GraphicsPath never extends beyond that.
This is what I get on my machine (and the DPI should have nothing to do with it since you're using the same coordinate space for the clipping region and the drawing region).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
yes, it looks very good on the picture - exactly how i want it. but to my utter dismay i cannot achieve this locally. i tried through vs.2003, then with command line csc.exe - nothing helps, and all i do is copy & paste the code you posted ... amazing .... im using .Net Framework v.1.1.4322..an idea that just came up - could you post your compiled exe file? i decided to upload mine too, here.
Change: this is insane - i run the application on another machine and it is fine there! so from the very beginning the problem was in the configuration on my machine, which is obvious now, because from the start my code was exactly as the one you posted. i guess i'll have to reinstall stuff.... thanx for your patience and support! have a very merry Christmas !
|
|
|
|
|
Good to know it's working. I just wanted to state that whether you use VS.NET or csc.exe there isn't any difference. VS.NET does not work "magic" like VS did for VB6 (the .frm files weren't the easiest to edit by hand). VS.NET uses the CodeDom to serialize code and the compilers use the same code to compile source. The VC++ compiler, on the other hand, is different between VS.NET and the Platform SDK, the latter of which doesn't have as good as optimization as the VS.NET compiler.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
any idea why i have different results on different pc-s?
my development pc is windows 2k server, i reinstalled the os, .net framework, .net sdk, and still cant get a correct window.
no problems though on the xp i run on it for test
|
|
|
|
|
As I mentioned before, it could be your DPI (dots per inch, or PPI for pixels per inch in some other countries/regions). Check your monitor settings. Since you're using pixels for both GraphicsPath s I don't see how this would be a problem, though, so long as you have no form border.
The Framework itself is agnostic to the platform (for those classes - like most - that are supported by every Windows platform) so its settings on the machine that are affecting your Form . Without being there on your computer it's hard to say.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have a question and I think it's so trivial:
how can i update the database binded to the data grid when I change or edit any record or add a new record.
I know how to retrieve data from the database and display it into the grid , but i need to update back the database with any update or addition to any record.
Thank you so much.
|
|
|
|
|
Read the DataAdapter.Update method documentation[^], which includes a lot of information about how to both fill a DataSet from a database to be bound to a DataGrid , as well as how to update the database from the changes in the DataSet using the Update method.
The DataSet class - or rather the DataTable instances that it contains - can track changes to the tables. Do not call DataSet.AcceptChanges before calling DataAdapter.Update and the database is updated appropriately as long as you've assigned your UpdateCommand , InsertCommand , and DeleteCommand properties on the derivative DataAdapter (like SqlDataAdapter ) correctly.
It's also important to mention that for the InsertCommand you should also combine it with a SELECT statement (separated by semi-colons, as with most SQL expressions) so that auto-generated fields are updated to their appropriate values after inserting the records into the table in the database.
The example referenced above also includes example source. For simple SELECT statements (assigned to the required SelectCommand , you can use the appropriate command builder (like the SqlCommandBuilder ) to generate the other three statements. More complex statements require that you manually construct the expression.
You can also get a lot of this for free from the designer. If you add a server reference to an RDBMS in the "Server Explorer", you can drag and drop a table, stored procedure, or view onto your Form or UserControl to create a connection and command object. You can then drag a DataAdapter derivative component from the "Data" toolbox category onto the designe and configure that programmatically. From that you can generate a typed DataSet (for faster look-ups and type safety). You can do those last two steps in reverse as well.
Dragging and dropping the right components allows you to data-bind a DataGrid through the designer with minimal code. At the are minute, the following lines (or similar, depending on your field names) are required:
sqlDataAdapter1.Fill(dataSet11);
dataGrid1.DataSource = dataSet11; The names above are what the default names may look like if you were to just accept all the default names, which isn't recommended since they are not self-descriptive which always improves code readability and decreases coding errors due to non-descript variable names.
For more information about how to do this using VS.NET, read Displaying Data Sources in Server Explorer[^] and Windows Forms Data Architecture[^] in the VS.NET product documentation. And as I always recommend, take a look at the source files to see what the VS.NET designer wrote to your source files. This includes showing all hidden files (click on the "Projects" menu, and check "Show Hidden Files") and expanding regions (collapsable regions of source code) so that you can see all the source code. Everything you do in the designer serializes to either code or some data file, so nothing should be "behind the scenes" so long as you look in the right place.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I have to display some xml document text in a richtextbox. All is ok except the formatting. Is there any usercontrol or plugin to do so?? The problem on hand is the xml document is in memory, not file. Moreover, this text will be changing based on the values of some comboboxes, ect. So, I cannot write to a file.
Please help.
Cheers
CNU
|
|
|
|
|
Hallo,
I am using the TcpChannel class in .Net Remoting. Does anybody know how to add authentication (username and password), or is it only available for the HttpChannel class.
Thanks for your help,
Björn
|
|
|
|
|
U could use CallContext to send the user info to the server application everytime u call a remote object.
Check out more about this here: CallContext[^]
|
|
|
|
|
Is their a way to add new properties to windows folder using C# .Eg I need a description property for folder where in I can type in some description relevant to the folder
Umesh.b
|
|
|
|
|
Whether or not it's possible has little to nothing to do with the language or framework. The file system does not expose an extensible system for defining properties for folders, though there is support using OLE streams for files. Windows NT provides a default OLE stream implementation for the "\005SummaryInformation" stream, while some formats - like Word Documents, MP3s, etc. - support their own implementation through a persistent file handler configured in the registry for that file class.
All this functionality is defined natively, however, and requires that you P/Invoke the necessary native APIs and define managed versions of native COM interfaces (using the ComImportAttributE , InterfaceTypeAttribute , and GuidAttribute ). There are projects documented here on CodeProject for doing just that.
For information about OLE streams and the "\005SummaryInformation" stream, I suggest you start by reading Properties and Property Sets[^].
To note, the default implementation that you see under the "Summary" tab in Windows Explorer for file properties uses alternative NTFS data streams. Custom handlers like that for Word actually store the information in the Word Document itself, which is how Windows 9X can see them, since Widnows 9X supports neither NTFS or alternative data streams (which is specific to NTFS). For MP3 files, for example, this information is reflected by the ID3 tags embedded in the MP3 file itself.
The documentation above references the native API functions and COM interfaces you need, and there's quite a bit. Just declaring these isn't enough, however, since you need to understand what an OLE stream is and how to access it. There are a couple different types of storage mediums, like IStorage and IStream . Streams (IStream ) may actually be contained within a compound storage structure (IStorage ), so checks are necessary to determine how you parse extended information.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello,
I am in the process of writing a "shrink wrapped" software product and I would like:
1. the end user to be able to define all of the labels/menu captions/error messages at runtime.
(eg. a customer may want to change the label 'Client' to 'Customer' etc. That way, 2 English speaking customers can have different captions to suit their own terminology. And 3 Portugese customers can do something similar and so on...)
2. the application to use locale-based dates/number formats.
3. the resource strings to be kept in xml files - not compiled into satellite dll's
Has anyone seen an article/sample app on the web anywhere that explains how to do this?
I basically want the end-user to be able to define their own terminolgy (if required) for any label or string that gets displayed to them but at the same be multi-culturally aware.
Thank you,
Daffrey
|
|
|
|
|
Hi,
I can't help you for all your points. But for point 2 about using the locale-based dates/number formats.
You can use Globalization and Localization. The System.Globalization namespace provides you with a number of classes that allow you to retrieve, make use and change the culture that your application code i susing to format dates, numbers and strings. The culture is set cia the Regional options. Localization means that you make use of these settings within your application. Every culture is defined by a 2 letter lowercase language code followed by an optional 2 letter uppercase Country code (f.e. nl-BE represents the Belgium Dutch regional setting.
You can ask the info using the globalization namespace. Then you can use the CultureInfo class.
<br />
Me.Label1.Text = CultureInfo.CurrentCulture.Name<br />
Me.Label2.Text = CultureInfo.CurrentCulture.DisplayName<br />
For the other items, you should create an kind of admin screen, where your users can define their word. Save this to your XML file and read this XML file.
I prefer to define by meyself the possibilities. Create languege textfile with everything translated. Use then resgen.exe to create your resourcefiles of each text file.
You can also work with XML-based resource files.
For this create your project, right click to add a new item and choose an Assembly Resource File . Add one for every language support. These files are XML files. Your job is to store the resources (name/value) in the data element. You can do this directly or using a dataset. Again use resgen.
As you can see, all of them are using regen to compile theses resX files into binary resource files. Only the first option isn't doing this.
Hopes this helps you a bit.
|
|
|
|
|
Thank you for your reply. I was originally thinking that I had to put every string into the "custom terminology" xml file, but I guess you are right. I probably only need to put in 30 or so words that end-users can configure based on their own terminology.
Some people might call a job a task, some might call it an issue and others may call it a fix.
I think I'll need to write template-based error messages. So an error message may look like:
"You can't delete the <<job>>. Permission Denied."
And then I'll just grab the <<job>> string from the "custom terminology" xml file...
Do you have any thoughts on whether it is better to put cultural resource strings for each language into 1 xml file? I haven't written a multi-lingual app yet, but I would imagine it would be easier to send 1 xml file per language to a translater rather than 1 form resource file that .NET normally uses....
Thank you for your reply.
Daffrey
|
|
|
|
|
You should start by reading Developing World-Ready Applications[^] in the .NET Framework SDK.
You should also understand the difference between globalization and localization, the former being how dates, times, and numbers are formatted, while the latter is how text is read according to the current language. Respectively, each is represented by CultureInfo.CurrentCulture and CultureInfo.CurrentUICulture , which could easily be different.
Developing a world-ready application using VS.NET is very easy. Develop your user interface, then use the PropertyGrid with the entire Form selected to set "Localizable" to true , then select the language. The neutral language is in whatever language you've developed the application (like "en-US" for U.S. English), so do not use that language. The neutral text will be compiled into resource files and embedded into your primary assembly (the assembly with the IL module(s) that is your compiled code), while any other languages are compiled into satellite assemblies. To make look-ups faster, you should define for your assembly an assembly-level attribute named NeutralResourcesLanguageAttributE using the locale/language in which you developed your application originally, like so:
[assembly: NeutralResourcesLanguage("en-US")] This will save a separate look-up for satellite assemblies when that particular language is the current locale and language. This is especially important if you're deploying your managed code via touchless deployment over the web.
I architected a solution using this concept, though I didn't use VS.NET because it's rather inefficient for enterprise applications. This will be greatly improved in Visual Studio 2005 using the ComponentResourceManager instead of the ResourceManager at design-time. Both classes have been defined since .NET 1.0, but the designer - up until VS 2005 - has been using the ResourceManager which can bloat your codebase by localizing every property attributed with the LocalizableAttribute , which is quite a few.
Even after compiling, either you or your clients can use the Winres.exe[^] tool. This only works if you use VS.NET's localization designer, or hack your .ResX files to make it look like VS.NET created the files.
There are a few articles on localization here on CodeProject, so I urge you to also search for them. For just localizing an application, however, it's quite easy. Use the VS.NET designer to localize an application and view what the designer did (it is, after all, just code and XML files (.ResX files, which are compiled into .resources files using the same functionality as the command-line tool resgen.exe). To make it easier, show all hidden files by clicking on the "Project" menu, then "Show Hidden Files" (or something similar to that).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi Heath,
Thank you very much for replying to my post, I really appreciate it.
Do you have any thoughts on whether it is better to put cultural resource strings for each language into 1 xml file? I haven't written a multi-lingual app yet, but I would imagine it would be easier to send 1 xml file per language to a translater rather than 1 form resource file that .NET normally uses....
However if this was done then it would be more work and a custom resource load routine would be required for each form.
The normal .NET way is to set the form localizable property to true and then select the language and go off and enter all of the labels for that language... To me that seems problematic because:
1. The same caption might be used on more than one form. If one developer has to update all of the "Name" captions on every form, then the chances of them missing one or more could be high for an application with many forms.
2. How does that work in practice for a translater? Does the translater need a copy of VS.NET installed and they go through each and every form in the designer? Or do you set the default language for each form. And if your application has 50 forms, then you send 50 resource files to a translater?
Did you face any of these issues when you did your multi-ligual application?
Cheers,
Daffrey
|
|
|
|
|
Normally you should have one resource file for each language. So when having three languages, you should have 3 resource files.
For your other question, I think (but I'm not sure) you can use the same caption for more than 1 form. So this should be no problem.
For the translator, you don't have to send 50 resource files but only the number of your languages. In these resource files everything is kept together for that language and as far as I know, your translator doesn't need a copy of VS.Net. As long as you give him the not compiled resource files, because these are XML files.
|
|
|
|
|
What you send to the translators doesn't necessarily have to be what you compile into resource files, so do whatever makes it easier. Since they are XML files (and you can also use plain text files using key=value pairs, but then you can only localize strings and not any Type that is attrbuted with a specific TypeConverter ), you can do just about whatever you want.
When you compile the resource files, however, they must be compiled into separate satellite assemblies. These satellite assemblies are identified by a specific culture.
Take a fully-qualified assembly name:
System, culture=neutral, version=1.0.5000.0, publicKeyToken=b77a5c561934e089 Notice the neutral? Primary assemblies (those assemblies that contain the IL module(s)) must always be neutral (but can contain your neutral language, which is why I mentioned using the assembly-level attribute NeutralResourcesLanguageAttribute for faster look-ups). Satellite assemblies replace "neutral" with whatever locale/language for which they were compiled.
Both the ResourceManager and the ComponentResourceManager (which extends the former) look-up resources in satellite assemblies using this information. You could create your own resource manager classes to look for resources in a single assembly, but there's so many problems with that.
It's inflexible and bloats the size of your assemblies when N-1..3 languages are necessary for any particular user (1..3 denotes cases when have locale-specific resources, which fallback to language-specific resources, which fallback to neutral resources). You also loose the ability to integrate with visual designers, unless you plan on implementing your own plugins for each designer instead of making the designers work for you (which is how the ComponentModel currently works).
Be sure to read-up on the classes I've mentioned as well as the links I gave you. It explains a lot of information.
Just going through an example of localizing a simple sample application and examining the code really helps, too. Create a new project, throw some controls on the form, assign some text, then localize it using the steps I've mentioned. Examine the source, compile the project, and examine the output. You can learn a lot from such an example.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi all,
Do the SQL Server CE on Pocket PC have the capability of recording locking ?
Thanks
|
|
|
|
|