|
It doesn't sound strange to me, since RGB is a 24 bit value, even if computers like powers of 2. If no color table is used, then the 24 bit value needs to be encoded as a 16 bit color which is 5 bits for each color (red, green blue), 1 bit unused.
I may be not completely right with that.
E.g. a 16 bit color can be converted to a 32 bit value with:
Color32 = ( (((Color16 >> 10) & 0x1F) * 0xFF / 0x1F) |<br />
((((Color16 >> 5) & 0x1F) * 0xFF / 0x1F) << 8) |<br />
((( Color16 & 0x1F) * 0xFF / 0x1F) << 16));
Looks weird. A 16 bit color may look like tihs.
<br />
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 <- Bits<br />
U R R R R R G G G G G B B B B B <- Color<br />
U = Unused<br />
R = Red<br />
...<br />
|
|
|
|
|
thanks for the explaination - i kinda get what you mean. One thing i don't understand, however, is the color16 and how to get the final value into a "Color" obj??
cheers!
|
|
|
|
|
IIRC rather than wasting a bit the green channel has 6 bits instead of 5 like the red/blue. I've no idea what makes green special.
|
|
|
|
|
yepp you are correct about the extra green bit..
because the human eye is more sensitive to see variations of green (i guess since our tree climbing/plains crawling days)
//Roger
|
|
|
|
|
The human eye is more sensitive to differences in green.
|
|
|
|
|
Hi there.
In order to create a class for a chat application - like readonly textbox that inherits the System.Windows.Forms.RichTextBox, I am trying to use a predefined color table (IRC-like textbox) in the RTF code.
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Fixedsys;}}<br />
{\colortbl ;\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue139;\red0\green100\blue0;\red255\green0\blue0;\red128\green0\blue0;\red128\green0\blue128;\red255\green165\blue0;\red255\green255\blue0;\red144\green238\blue144;\red95\green158\blue160;\red0\green255\blue255;\red0\green0\blue255;\red255\green192\blue203;\red169\green169\blue169;}<br />
"\viewkind4\uc\pard\f1\highlight1\cf2 This line uses the first color as foreground- and the second color as background-color on this line\par<br />
\highlight0\cf0 This line uses default colors.}
After I set the new RichText (control.RTF = variable), the RichTextBox automatically reformats the raw rich text I manipulated just a few ticks ago. It removes all not yet used colors from the colortable and even reorders it.
Is there a way to override/avoid automatic reformatting of the raw richtext (control.RTF)? I don't want to use the techinque where the last added text is selected, some forecolor applied, via API some background color applied, ...
Daniel
|
|
|
|
|
I've got a UserControl that responds to the MouseEnter and MouseLeave problems, making a highlight effect as the mouse passes over, however the controls within my control fire the MouseLeave event when the mouse moves from my control into the child control. Is there any way to make these controls "invisible" to mouse events?
Thanks in advance,
Peter
|
|
|
|
|
You could override the WndProc() method of the control to ignore the message.
|
|
|
|
|
Hmmm, how would that work? I don't want to completely ignore the MouseLeave event of the control, I just want to ignore the MouseEnter event of the child controls, wouldn't the MouseLeave event of the user control still get fired?
|
|
|
|
|
Hi guyz,
I got a quick question regarding DataSets and RowState. In the
following code sample I populate a DataSet, then modifies two rows,
and call the DataRow.AcceptChanges(). But when i retrieve the
Rowstate of those edit Rows it says "UNCHANGED".
shouldn't be "MODIFIED". If not, then WHY?????
here is the code :
namespace DSEditEx
{
///
/// Summary description for dsClass.
///
public class dsClass
{
//private variable which represents a DataSet <ds>
private DataSet ds;
public dsClass()
{
//instantiate the <ds>
ds = new DataSet();
try
{
//Initialize ds
ds = new DataSet();
//define the first data table
DataTable tblCustomer = new
DataTable();
//define and add columns to ds
DataColumn custID = new
DataColumn();
custID.ColumnName = "CustomerID";
custID.ColumnName = "Customer ID";
custID.AllowDBNull = false;
custID.DataType =
System.Type.GetType("System.Int16");
tblCustomer.Columns.Add(custID);
DataColumn fn = new DataColumn();
fn.ColumnName = "FirstName";
fn.Caption = "First Name";
fn.AllowDBNull = false;
fn.DataType =
System.Type.GetType("System.String");
tblCustomer.Columns.Add(fn);
DataColumn ln = new DataColumn();
ln.ColumnName = "LastName";
ln.Caption = "Last Name";
ln.AllowDBNull = false;
ln.DataType =
System.Type.GetType("System.String");
tblCustomer.Columns.Add(ln);
//adding the table -> ds
ds.Tables.Add(tblCustomer);
//load some data into datatable 1
-> tblCustomers
DataRow r;
for(int i=0; i < 10; i++)
{
r = ds.Tables[0].NewRow();
r[0] = i;
r[1] = "Farhan_" + i;
r[2] = "Munir_" + i;
tblCustomer.Rows.Add(r);
}
}
catch(Exception ex) {
Console.WriteLine(ex.ToString()); }
}
//public method which illustrates how to edit
values
//in the datarow. How to check the state of the
DataRow
public void DemoDSEdit()
{
try
{
//we are going to modify Row[0]
DataRow editRow =
ds.Tables[0].Rows[0];
//we are going to modify the first
and last name
editRow[1] = "John";
editRow[2] = "Doe";
//Now check the state of all Rows
//Note we haven't commit any
changes yet
Console.WriteLine("Checking the Row
State");
for(int i=0; i <
ds.Tables[0].Rows.Count; i++)
Console.WriteLine("State of
Row[" + i + "] : " + ds.Tables[0].Rows[i].RowState.ToString());
//Now Commit changes and again
check the State of Row
Console.WriteLine("\nCommitting
Changes and Checking the RowState");
editRow.AcceptChanges();
for(int i=0; i <
ds.Tables[0].Rows.Count; i++)
Console.WriteLine("State of
Row[" + i + "] : " + ds.Tables[0].Rows[i].RowState.ToString());
//Modify the Row[0] again
editRow = null;
editRow = ds.Tables[0].Rows[1];
editRow[1] = "Jane";
editRow[2] = "Munir";
Console.WriteLine("\nCommitting
Changes and Checking the RowState");
editRow.AcceptChanges();
for(int i=0; i <
ds.Tables[0].Rows.Count; i++)
Console.WriteLine("State of
Row[" + i + "] : " + ds.Tables[0].Rows[i].RowState.ToString());
}
catch(Exception ex) {
Console.WriteLine(ex.ToString()); }
}
}
}
----------------------------------------
OUTPUT is :
----------------------------------------
Checking the Row State
State of Row[0] : Added
State of Row[1] : Added
State of Row[2] : Added
State of Row[3] : Added
State of Row[4] : Added
State of Row[5] : Added
State of Row[6] : Added
State of Row[7] : Added
State of Row[8] : Added
State of Row[9] : Added
Committing Changes and Checking the RowState
State of Row[0] : Unchanged
State of Row[1] : Added
State of Row[2] : Added
State of Row[3] : Added
State of Row[4] : Added
State of Row[5] : Added
State of Row[6] : Added
State of Row[7] : Added
State of Row[8] : Added
State of Row[9] : Added
Committing Changes and Checking the RowState
State of Row[0] : Unchanged
State of Row[1] : Unchanged
State of Row[2] : Added
State of Row[3] : Added
State of Row[4] : Added
State of Row[5] : Added
State of Row[6] : Added
State of Row[7] : Added
State of Row[8] : Added
State of Row[9] : Added
|
|
|
|
|
If you want the rows to remain as MODIFIED, do not call AcceptChanges(). By calling AcceptChanges() you are commanding the data row(s) to end the current edit.
|
|
|
|
|
The idea is that you perform the editions on the rows (add, delete, modify) and then, somewhere else, you check which rows have been modified and save only those to the database. You then call AcceptChanges . Then, after the next set of changes, only the newly-changed rows will require saving to the real database.
If you use a data adapter, it automatically calls AcceptChanges in Update after updating the database.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I m having a problem, where i need to display shared folders of a computer in C#. Like i enter a computer name and it has to display shared folders in windows explorer. i don't know how to do it? can anybody guide?
Amar
|
|
|
|
|
You'll need to utilize the Windows Shell APIs. This site has several articles on how this is done, search for 'shell' C# articles and you should get a few hits.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Conversation With a Muslim
Judah Himango
|
|
|
|
|
I wonder if u can help me in solving the following problem:
I want to divide a number by 10 and get the result as the highest number.
Let me explain with following examples:
13/10 = 2 and
27/10 = 3
How can I achieve this
thanks
|
|
|
|
|
Math.Round( (a / 10) + .5 ) ?
David
|
|
|
|
|
How about (int)((n+9)/10) ?
You can even skip the (int) if your n already is an int...
mav
|
|
|
|
|
Not knowing C# I can't give you the proper code, but in pseudo-code:
If (x - int(x)) > 0.00
return int(x) + 1
else
return int(x)
Unlike the rounding function, which will round down as well as up, this will return either the original input, if it is an integer, or the next higher integer if it contains any fractional part at all. You may still get some goofy errors, though, because the input might have some small fractional part due to previous calculations. There are ways to get around that, but they may not be necessary depending upon your application.
"...putting all your eggs in one basket along with your bowling ball and gym clothes only gets you scrambled eggs and an extra laundry day... " - Jeffry J. Brickley
|
|
|
|
|
|
gee *cough* I'll join, assuming x is an int..
int n = (x / 10) + (x % 10 > 0 ? 1 : 0);
*lame around* \o/
|
|
|
|
|
While walking at the abyss of insanity, I found out, you can use something completely senseless, far away from anything that could be called useful. Evalute strings.
int x = 27;<br />
int n = 0;<br />
string seperator = System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;<br />
<br />
double d = ((double)x / 10.0d);<br />
string s = d.ToString("F1");<br />
<br />
if (!s.Substring(s.IndexOf(seperator) + 1, 1).Equals("0"))<br />
{<br />
d += 1.0d;<br />
s = d.ToString("F1");<br />
}<br />
<br />
n = int.Parse(s.Substring(0, s.IndexOf(seperator)));
|
|
|
|
|
Daniel, you frighten me!
mav
|
|
|
|
|
You are outta control!
|
|
|
|
|
Umm.. yes, I got it out of the abyss of insanity, I'm walking quite close to it but usually don't use anything from there
Even if it works, it's awful, but it works
I also like the ASM version from Niklas Ulvinge
|
|
|
|
|
Wouldn't this be machinecode optimised:
n >> 1;
n /= 5;
n++;
In asm it would be like:
;number in AL
SHL AL,1 ;2 clocks
MOV BL, 5 ;4 clocks
DIV BL ;0-90 clocks
INC AX ;2 clocks (saved one clock by using AX insted of AL...)
;
;I'm not familiar with how much the div instruction takes in time but
;since it is only 5 I think's it's not much.
;
The PROgrammer Niklas Ulvinge aka IDK
|
|
|
|