|
I've put together a component that, upon a certain action, a window opens. I am opening that window directly below the component, aligned with the bottom edge. It works great and exactly as I need it to...until the UC form is contained within a mdicontainer.
I am currently determining the position to place the window by looking at the position of the current component and its parents. Apparently with mdicontainers, the child form is a parent and I cannot get the appropriate screen position because the application form creates an unknown offset.
private void GetRefLocation(Control controlIn, ref int top, ref int left)<br />
{<br />
<br />
Control controlParent = controlIn.Parent;<br />
Form parent = this.FindForm();<br />
<br />
if (parent == controlParent)<br />
{<br />
top += parent.Top;<br />
left += parent.Left;<br />
}<br />
else<br />
{<br />
int addHeight = 0;<br />
System.Type a = controlParent.GetType();<br />
string b = controlParent.GetType().FullName;<br />
if (controlParent.GetType().FullName == "System.Windows.Forms.Panel")<br />
addHeight = ((Panel)controlParent).BorderStyle == BorderStyle.None ? 0 : (((Panel)controlParent).BorderStyle == BorderStyle.FixedSingle ? 1 : 2);<br />
<br />
top += controlParent.Top + addHeight;<br />
left += controlParent.Left;<br />
GetRefLocation(controlParent, ref top, ref left);<br />
}<br />
}
What do I really need to do to determine the position within the screen? I followed a couple trails involving GDI but I never found a way that I can set component.Location based on the screen position, let alone position of another component.
Thanks
|
|
|
|
|
dbetting wrote:
What do I really need to do to determine the position within the screen?
Use the PointToScreen and PointToClient methods of Control class to convert a location from client coordinates to screen coordinates respectively the other way round.
www.troschuetz.de
|
|
|
|
|
Thank you very much. With the code below, I eliminated the entire routine previously shown. I suspected it would end up being something simple.
Point newPos = PointToScreen(this.Location);<br />
newPos.Y = newPos.Y - this.Top + this.Height;<br />
newPos.X = newPos.X - this.Left;<br />
popup.Location = newPos;
Once I had screen position, all I had to do is offset the position by the local form position and it seems to pass the test regardless of depth of the User Controls on the form.
Thanks.
|
|
|
|
|
|
Sorry for the newbie question! I'm trying to write hex values into a file.
I started out using a streamwriter and writing a string:
"\x48\x41\x53\x48\x0D\x0A\xff\x00\x00\x01"
This worked fine, except that when looking at the output file in a hexeditor I got
48 41 53 48 0D 0A C3 BF 00 00 01
Where is should have read FF there was C3 BF!!
The same happens if I create an array and write that using a binary writer, ie:
char[] temp = new char[] {'\x48','\x41','\x53','\x48','\x0D','\x0A','\xFF','\x00','\x02','\x00','\x00','\x00','\x01','\x00','\x00','\x00'};
The only way I can do it is to convert all the hex to decimal and write it that way with a binarywriter:
byte[] temp = new byte[] {72,65,83,72,13,10,255,0,2,0,0,0,1,0,0,0};
But this is a pain, can anyone tell me how I SHOULD be doing this.
Thanks, in advance,
Chris
|
|
|
|
|
Any TextWriter or TextReader uses an Encoding to encode and decode bytes from and to text. More than likely it is the encoding that decided there was a better alternative, though that's just an educated guess.
You might consider using the ASCIIEncoding which is always single-byte characters, so 0xC3 0xBF isn't replaced with a "more suitable" character.
What are you writing binary characters to a file, though? If you are just trying to write the equivalent Unicode characters, you can specify Unicode in C# using \uXXXX .
Otherwise, you could use a Stream to write the entire binary file, and when you need to write text use the Encoding you find appropriate, like ASCIIEncoding or UTF8Encoding (which is nice, since for the ASCII character set (first 128 bits) it looks like an ASCII file but can handle other characters sets like Unicode without using a codepage).
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]
|
|
|
|
|
Heath,
Thanks for that comprehensive reply! I have tried changing the encoding method, but to no avail it changes the output - but it still isn't right!
Here is the code I am currently playing with:
FileStream outputFile = new FileStream(destination, FileMode.CreateNew);
BinaryWriter outputBin = new BinaryWriter(outputFile,System.Text.Encoding.ASCII);
char[] temp = new char[] {'\x48','\x41','\x53','\x48','\x0D','\x0A','\xFF','\x00','\x02','\x00','\x00','\x00','\x01','\x00','\x00','\x00'};
outputBin.Write(temp);
The ouput it produces is:
ASCII:
48 41 53 48 0D 0A 3F 00 02 00 00 00 01 00 00 00
Which is closer to what I want (in that FF is replaced with only 1 char not 2 as previously), but is still wrong.
I tried unicode as well, just for giggles, and that did work and produced an FF as required. Unfortunately the file I wish to write is to be read by another piece of software which requires a very specific format(not unicode).
Been at this hours now - brain melting....
|
|
|
|
|
I definitely think it's the encoding, especially if it worked under Unicode. If you're trying to write binary data, though, you can just use the FileStream itself instead of a BinaryWriter . You also should take a look at the using statement to make sure the streams are disposed, like so:
using (FileStream file = new FileStream(...))
{
} Sorry, just something I really think people should do when working with objects with ties to native resources.
Anyway, anything over 0x7f using encodings like UTF8 mean that 2 bytes should be used. IIRC, some codepages work this way, too. So, make sure you're using the right codepage (you can pass this to the Encoding class you need).
If I were you - and I do this a lot - dig through the IL using ildasm.exe or a decompiler like ".NET Reflector" to trace through the code itself to see what happens when you call BinaryWriter.Write or BinaryWriter.WriteLine and see how the Encoding class is used. Then see how the Encoding class derivative you're using works.
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 my query for my dropdownlist
select PD_REF, PD_DIRECTION FROM TBPARAMDIRECTION
PD_REF PD_DESCRIPTION
---------- ------------------------------
0 ParamUnknown
1 ParamInput
2 ParamOutput
3 ParamInputOutput
4 ParamReturnValue
This is my main query for my main the datalist is
SELECT CM_REF, PM_INDEX, PM_NAME, PM_DESCRIPTION,
PM_TYPE, PM_CONTENT, PM_DIRECTION, PM_LENGTH FROM TBPARAMETERS
How can I display the dropdownlist.
Can someone help me with the query.
|
|
|
|
|
Are you asking how to bind this data to a ComboBox ? Use a DataAdapter implementation (like SqlDataAdapter , if you're querying a SQL Server RDBMS) and assign the resultant DataSet to ComboBox.DataSource :
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT CM_REF, PM_INDEX, PM_NAME, PM_DESCRIPTION" +
"PM_TYPE, PM_CONTENT, PM_DIRECTION, PM_LENGTH FROM TBPARAMETERS";
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
try
{
adapter.Fill(ds);
}
catch (Exception ex)
{
}
if (ds.Tables.Length == 1)
{
comboBox1.DataMember = ds.Tables[0].TableName;
comboBox1.DataSource = ds;
}
} You could also just assign ds.Tables[0] to DataSource , but that can be pretty inflexible in scenarios when you want to related data from the same DataSet in other controls on the form.
If this is not what you're asking, please clarify.
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 my query for my dropdownlist
select PD_REF, PD_DIRECTION FROM TBPARAMDIRECTION
PD_REF PD_DESCRIPTION
---------- ------------------------------
0 ParamUnknown
1 ParamInput
2 ParamOutput
3 ParamInputOutput
4 ParamReturnValue
This is my main query for my main the datalist is
SELECT CM_REF, PM_INDEX, PM_NAME, PM_DESCRIPTION,
PM_TYPE, PM_CONTENT, PM_DIRECTION, PM_LENGTH FROM TBPARAMETERS
I must include something in my main grid query to link the two?
But What?
How can I display the dropdownlist.
Can someone help me with the query.
How can I display my dropdownlist also?
This is my query for my dropdownlist
select PD_REF, PD_DIRECTION FROM TBPARAMDIRECTION
PD_REF PD_DESCRIPTION
---------- ------------------------------
0 ParamUnknown
1 ParamInput
2 ParamOutput
3 ParamInputOutput
4 ParamReturnValue
This is my main query for my main the datalist is
SELECT CM_REF, PM_INDEX, PM_NAME, PM_DESCRIPTION,
PM_TYPE, PM_CONTENT, PM_DIRECTION, PM_LENGTH FROM TBPARAMETERS
I must include something in my main grid query to link the two?
But What?
|
|
|
|
|
Wait, so you want a ComboBox embedded in a DataGrid ? You really need to explain yourself a little better and use actual class names, since "dropdownlist" isn't a control, nor is "grid". I can only assume you mean a ComboBox and a DataGrid .
Search for "ComboBox" and "DataGrid" in a search engine. Several people have written such DataGridColumnStyle -derivatives.
If you want to "link" (again, please use technical terms, like "relate" as in "relational data") two DataGrid s together, you have to establish a DataRelation between two DataTable s in the same DataSet . The easiest way to do this is to create a typed DataSet in Visual Studio. You can do this by right-clicking on your project (or project folder), select Add -> Add New Item and select DataSet. Add two elements and some fields that match your tables. Using the designer right-click and add a new relation between a child and parent key. You can also do this programmatically using a non-typed DataSet by adding DataTable s, then DataColumn s to each table, then a DataRelation (which includes an example in the .NET Framework SDK documentation) between your DataColumn s from the two different tables.
To fill this DataSet , make sure that you use DataAdapter.Fill(DataSet) and add DataAdapter.TableMappings s for the result set names and your actual tables names (since the result set names are, by default, "Table", "Table1", "Table2", etc.).
Finally, for each DataGrid for which you want to relate the data, set the DataMember property of the parent relationship to the table name of the parent table (as string). For the second, child DataGrid , set the DataMember to the "parenttable.relationship" name.
Finally, assign the DataSet as the DataSource for both. Now when you select a row in the parent DataGrid , the related records in the child DataGrid are displayed.
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 was using this successfully at work last week to document C# applications. So I thought I'd try it at home.
It generates the HTML files OK but the .chm file refuses to display pages "Page cannot be displayed" error. Any ideas?
At work I was using Visual Studio 2003 on Windows Server 2003 running inside MS Virtual PC 2004 on a Win 2k SP4 box.
Here I've just tried it with VS 2003 on Win 2k SP4. I also have an XP Pro box but I've not tried it there yet.
Kevin
|
|
|
|
|
NDoc 1.2 is very buggy. Version 1.3 beta is less buggy. http://ndoc.sourceforge.net/[^]
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
I discovered that the Help compiler has a problem with long paths. So specifying the output directory as a shorter path, e.g., c:\development\test, solves the problem.
Kevin
|
|
|
|
|
If you have issues with a specific application or library, you need to ask on their support pages. NDoc has both support and bug tracker pages, as do all projects hosted on SourceForge. Post your issues at http://sourceforge.net/tracker/?group_id=36057&atid=416078[^].
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 form with a system tray icon...now what i want is to hide the form when the user clicks the red cross(close button) of the window....when he double clicks the system tray icon...i will write....form1.show().....how do i hide the form when he clicks the close button on the top right corner of the form...
|
|
|
|
|
Mridang Agarwal wrote:
how do i hide the form when he clicks the close button on the top right corner of the form...
When the Close button on the top right of the form is clicked two events get fired. The Closing event and the Closed event.
Closing happens BEFORE the form is closed, while Closed happens AFTER the form is closed. The Closing event is usually used to pop up message boxes such as "Your file is not saved. Do you want to save it?". However you can do what you like with it, including cancelling the Close operation, you'll see there is a property in the event arguments for the closing event that permits you to stop the form being closed. Instead you will do your own thing to hide or minimise the form.
Does this help?
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
I don't reply to direct emails so I am answering you on the forum.
In an email Mridang Agarwal wrote:
no....i want to hide the form when he clicks the close button....i dont want to display any messages
....how do i do this....
That was simple an example of what is 'normally' performed in the Closing event. As I already said:
Colin Angus Mackay previously wrote:
However you can do what you like with it, including cancelling the Close operation, you'll see there is a property in the event arguments for the closing event that permits you to stop the form being closed. Instead you will do your own thing to hide or minimise the form.
So, as you see, in your event handler for the Closing event you cancel the form closing, and instead Hide the form.
private void NameOfFormClass_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel=true;
this.Hide();
}
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
hey colin....this may sound silly....ur names really catchy...like....colin McRae.....the World Rally Champioship driver...heheh.....anyways....i need...a bit a bit o hlp with a few more questions....what do i do...
|
|
|
|
|
Anonymous wrote:
anyways....i need...a bit a bit o hlp with a few more questions....what do i do...
Normally if you post the question on the relevant forum and if someone knows the answer then they will do their best to help you.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
I have a little problem with wav files. I'm trying to do a mixer with wav files, well the case is that when I mix them I divide every sample by the number of total wav's so that I don't overpass the 16 bit limit and divide them again for volume control. The resulting wav has a too low volume, does anybody know how to recover the volume without overpassing the 16 bit limit values?
|
|
|
|
|
IIRC, It is called normalising. You search through the wav for the highest value then from that you can work out a factor to multiply all the other values by to shift all the other values. However, by doing this you negate any effect of your volume control.
I would suggest that you add all the wavs together, ignoring the 16bit limit, then normalise, then adjust your volume. That way you won't lose any information. If you normalise upwards you get the audio equivalent of pixelation when you zoom in too far on an image.
So, if you discover that your absolute peek sample is 100000 [remember that negative peeks need to be taken into account, so use abs(sample)], you divide that by 32768. You'll get 3.052. Once you divide all your samples by this amount, the peek sample in your wav will fit just inside the 16bit limit.
You can then adjust your volume - of course if your volume is being adjusted on each of the input waves you should do this before mixing the inputs.
Does this help?
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
thanks a lot, it seem a logical and easy solution...and yes, better mixing ignoring the 16bit limit so that any information is lost. But just one more question: I have to mix waves changing particular volumes, so should I first divide every wav sample, the add them all, and then normalize, it's that ok?
thanks again
|
|
|
|
|
jeroni_brunet wrote:
I have to mix waves changing particular volumes, so should I first divide every wav sample, the add them all, and then normalize, it's that ok?
If each wav is to be mixed at a different volume, I'd change the volume first. However, I'd multiply up, again so information is not lost.
So, lets say we have 3 wavs, one with a volume of 25%, one with 75% and one with 90%. We would say that the first wav has a volume of 1, the second wave has a volume of 3 and the third has a volume of 3.6. We multiply each of the samples by the correct amount - with this method, the quietest wav will require no modification. All the wavs can then be mixed together, and finally normalised.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|