|
How I will convert the 20 to 0010 0000 format and I want retrieve the third bit (in this case 1)
from 0010 0000
|
|
|
|
|
I use this to retrieve a bit:
public bool GetBit(int bitOrder)
{
return Convert.ToBoolean(errorNumber & (0x1 << bitOrder));
}
|
|
|
|
|
What is errorNumber and bitOrder
|
|
|
|
|
Ooo.. sorry, I didn't change the variable name of my code.
int number = 20;
int bitOrder = 2;
bool bit = Convert.ToBoolean(number & (0x1 << bitOrder));
// 00010100 -> Bit 2 is true, bit 3 is false
// 76543210
Console.WriteLine(bit.ToString());
|
|
|
|
|
That's a nice code. By using that u can make ur own function
Like...
public bool GetBit(int No,int bitPos)
{
return Convert.ToBoolean(No & (0x1 << bitPos));
}
But be carefull (MSB->LSB) BitPos = 0 = LSB
regards,
Divyang Mithaiwala
System Engineer & Software Developer
|
|
|
|
|
I wanted to draw the lines with higher precision for one of my project. So instead of using point structure, I thought to make a use of pointF strucuture. I made one sample application to test how precision differs in case I use pointF strucutre then point. Following is the sample code which i written to draw a lines on my form :
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
e.Graphics.DrawLine(new Pen(System.Drawing.Color.Red),new PointF(20.0F, 100.0F), new PointF(100.0F, 100.0F));
e.Graphics.DrawLine(new Pen(System.Drawing.Color.Green),new PointF(20.0F, 100.51F), new PointF(40.0F, 100.51F));
}
As per above code, I tried to draw 2 lines with very minimal difference in y co ordinates. I was shocked to find out that pointF rounds the co ordinate value while drawing the line. As per above example, if I keep Y co ordinates for 2nd line between 100.00 to 100.50, I can see only one line drawn as lines are drawn with the same co ordinates. But if I keep the Y co ordinates for 2nd line even 100.51 then I can see two seperates lines. This means pointF strucutre rounded the y co ordinate value to 101 and that is why i could see two different line. I tried to check the things by increasing and decreasing the resolution of my screen but it didn't help. If such is the behaviour then there is no difference between the point and pointf and we can not get the better precision then 1 pixel while plotting a drawing.
Can any one pls explain me above behaviour? I want to draw the lines with higher resolution so can anyone give me the idea of how to achieve it? I hope I'm clear with my question and expectation?
|
|
|
|
|
It is impossible to get higher resolution than 1 pixel. That's the smallest point the hardware can draw, regardless of what the software asks for. The impact of rounding will vary (appear to take effect) differently on screens with a different pixel density (dpi), but pixel density can't be changed without changing the hardware.
|
|
|
|
|
Graham,
Thanks for your reply.
Rob Graham wrote: It is impossible to get higher resolution than 1 pixel
If we can not get resolution higher than 1 pixel then what is the need of having two seperates structures i.e. point and pointF. Merely passing the values in float doesn't make sense if internally it is going to get rounded off.
|
|
|
|
|
If you for an example use a transform that scales the graphics by 1000%, you can make use of the higher precision. The rounding will take place after the scaling but before the actual drawing, so if you specify a rectangle with the size 0.53 x 0.78, it will draw a rectangle with the size 5 x 8 pixels.
Have you tried to change the InterpolationMode and SmoothingMode of the Graphics object? That might change how the coordinates are rounded.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks for your reply Guffa.
I see a ray of hope from your reply. I have not worked extensively on GDI. So I'm not getting exactly what you are trying to say. Can you elaborate on your reply or send me some links or material which I can refer?
|
|
|
|
|
KrunalC wrote: So I'm not getting exactly what you are trying to say.
What about it didn't you get?
---
b { font-weight: normal; }
|
|
|
|
|
Hi All.
I have 2 time 1. After
2. Before
I need to know what is the different between those time.
I will explain - After can be like date and time as 07.06.06 16:54
Before can be like date and time as 08.06.06 15:54
What i need is to know what is the time that pass from the time Before until time After.
How can i found this time ?
I need to know for example how many second from one time to the other - or how many minutes...
Thanks.
|
|
|
|
|
You can use the System.DateTime struct and its Subtruct function.
Regards,
Shy.
|
|
|
|
|
ok , and how can i calculat the different of the times ?
Pass all the Time param ? ( i meen that check if the day is same / month / hour ) ? Is there any simple way ? Like Time1 - Time 2
|
|
|
|
|
DateTime tm1 = ...;
DateTime tm2 = ...;
TimeSpan ts = tm2 - tm1;
System.Console.Writeln ("Difference in mins = " + ts.TotalMinutes); /ravi
|
|
|
|
|
When a user opens a file associated with your program you may want the new instance to pass along the file to the first instance and exit. One problematic way of doing this is using the Visaul Basic MainForm.Invoke and StartupNextInstanceEventHandler. However, this library won't work with MONO/Linux and for some reason it connects to the network while invoking the thread, triggering a nasty firewall popup.
Is there any C# alternative or is it possible to improve on the code to avoid the network and mono problems? Please and Thank you!
using System;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;
class Program
{
[STAThread]
static void Main(string[] args) { new App().Run(args); }
class App : WindowsFormsApplicationBase
{
public App()
{
IsSingleInstance = EnableVisualStyles = true;
ShutdownStyle = Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses;
StartupNextInstance += new StartupNextInstanceEventHandler(NextInstance);
}
protected override void OnCreateMainForm()
{
MainForm = new Form1();
((Form1)MainForm).Args = new string[CommandLineArgs.Count];
CommandLineArgs.CopyTo(((Form1)MainForm).Args, 0);
}
protected void NextInstance(object sender, StartupNextInstanceEventArgs eventArgs)
{
string[] args = new string[eventArgs.CommandLine.Count];
eventArgs.CommandLine.CopyTo(args, 0);
MainForm.Invoke(new Form1.InstanceDelegate(((Form1)MainForm).processParameters), new object[] { MainForm, args });
}
}
}
public void processParameters(object sender, string[] args)
{
if (WindowState == FormWindowState.Minimized)
WindowState = FormWindowState.Normal;
if (args != null && args.Length != 0)
openFiles(args);
}
// Mikzi L. Freeman
|
|
|
|
|
Mikzi, it is possible to pass objects around to other threads:
void FooBar(object state)
{
object[] thePassedObjects = (object[])state;
}
ThreadPool.QueueUserWorkItem(FooBar, new object[] {"hello", "world", "!"});
You can pass objects to the UI thread by calling the Invoke or BeginInvoke on some Control:
delegate void OurDelegate(string s, object o, int i);
void OurFunction(string s, object o, int i)
{
}
....
myControl.Invoke((OurDelegate)OurFunction, "hello", new object(), 5);
|
|
|
|
|
This seems like a simple implementation using invoke, but I'm unsure of how to get a handle to the main instance form without using VB.net MainForm.
static void Main(string[] args)
{
bool granted;
using (Mutex mutex = new Mutex(false, "mutexName", out granted))
{
if (granted) Application.Run(new Form1());
else xxx.Invoke(new Form1.InstanceDelegate(xxx.processParameters), new object[] { xxx, args });
}
}
// Mikzi L. Freeman
|
|
|
|
|
Hi!
In order to be able to invoke a method on the first instance's form you've got to have a reference to this form, of course.
One idea would be to let the first instance register a remoting server and the second instance access this remoting server.
Perhaps this is done internally in VB.NET's MainForm, it could explain the firewall message.
You could use the new (for .NET 2.0) ipc channel instead of a tcp channel, perhaps this doesn't trigger a firewall alert.
Regards,
mav
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
The client server method does work. It solves the problems with not relying on Visual Basic libraries as well as working with Mono/Linux. It requires some coding however, and it needs the ip address and a port number. Might be possible to simplify the process further than this...
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
new App();
}
class App
{
private static Form1 mainform;
private Mutex mutex;
public App()
{
bool owned; int port = 1392;
mutex = new Mutex(false, "Form1", out owned);
if (!owned)
{
ChannelServices.RegisterChannel(new TcpChannel(), true);
string str = "tcp://" + Dns.GetHostEntry(Dns.GetHostName()).AddressList[0] + ":" + port + "/" + typeof(RemoteServer).GUID.ToString();
((RemoteServer)Activator.GetObject(typeof(RemoteServer), str)).ActivateInstance(Environment.GetCommandLineArgs());
}
else
{
ChannelServices.RegisterChannel(new TcpChannel(port), true);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteServer), typeof(RemoteServer).GUID.ToString(), WellKnownObjectMode.Singleton);
Application.Run(mainform = new Form1());
}
}
private class RemoteServer : MarshalByRefObject
{
public void ActivateInstance(string[] args)
{ args[0] = null; mainform.Invoke(new Form1.InstanceDelegate(((Form1)mainform).processParameters), new object[] { mainform, args }); }
}
}
// Mikzi L. Freeman
|
|
|
|
|
iwant to know the barcode font "the name of the bar code font"
|
|
|
|
|
|
I have a dll I'm coding in one solution, and a test project in another.
Does the referenced dll reloads in the test project, after recompiling the dll?
|
|
|
|
|
|
Partially, yes...
I don't want my dll to reference the test project.
I want my test project to reference the dll, and auto update every time I recompile the dll.
Is it possible?
|
|
|
|