|
Never printed graphics before, I am stuck in the beginning.
I've got some graphics elements, like rectangles and circles. They show OK on the screen. Now I need to print them keeping proper scaling: all sizes are in millimetres. And first question is: how do I print a rectangle 100 x 100 mm? What size on paper does this rectangle have:
gr.DrawRectangle(Pens.Black, 100, 100, 100, 100)?
I know it must be linked somehow to default printer's resolution, but I am lost: could not find anything useful in help.
(using C# in Visual Studio 2012)
Thank you
|
|
|
|
|
Set the Graphics.PageUnit[^] to mm:
gr.PageUnit = GraphicsUnit.Millimeter; And all subsequent drawing references will use mm instead of pixels regardless of the device being drawn onto. Note that this won't necessarily be accurate on a monitor, where the system doesn't really know what size it is anyway!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I have a dialog form, you can add or edit customers, the owner of the project choose to use a Guid value.
How do I write the public dialog function to accept a null value or a valid Guid?
I tried the ?, but got a conversion error, not suite sure what it means.
Then I get Guid is non nullable
public dialog_customerDetails(Guid? position)
{
InitializeComponent();
if (position != null)
{
_position = position;
}
}
Then in the calling form
Guid m_value= new Guid(item.SubItems[0].Text);
dialog_customerDetails dialog_CD = new dialog_customerDetails(m_value);
if (new dialog_customerDetails(null).ShowDialog() == DialogResult.OK)
|
|
|
|
|
Guid is a valuetype, which means that it can't contain a null value - only references can be null .
When you declare it as
Guid? m_value; You are declaring it as a different type altogether, so you can't assign a Guid? type value directly into a Guid - and you can;t convert a null from a Guid? to a Guid value anyway!
Instead of null , use Guid.Empty instead:
public dialog_customerDetails(Guid position)
{
InitializeComponent();
if (position != Guid.Empty)
{
_position = position;
}
} And use Guid throughout instead of Guid?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
oh It's that simple, I starting to get c# better now.
Guid.Empty
Say, could you look at my previous post below, post 3 on the way I loaded the data from the DAL?
If you have free time.
Just wanted to confirm that I'm on the right track before I write more of it.
|
|
|
|
|
The documentation for this is obscure and all over the place. I'm trying to get the solution open in THIS instance of VS:
using EnvDTE;
using EnvDTE80;
using System;
using System.Windows.Forms;
namespace EnvDTE_Test
{
class Program
{
static void Main(string[] args)
{
EnvDTE80.DTE2 dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.11.0");
try
{
Project prj = dte2.Solution.Projects.Item(1);
Projects prjs;
string msg, msg2 = "Global Variables:";
msg = "FileName: " + prj.FileName;
msg += "\nFullName: " + prj.FullName;
msg += "\nProject-level access to " + prj.CodeModel.CodeElements.Count.ToString() + " CodeElements through the CodeModel";
prjs = prj.Collection;
msg += "\nThere are " + prjs.Count.ToString() + " projects in the same collection.";
msg += "\nApplication containing this project: " + prj.DTE.Name;
if (prj.Saved)
msg += "\nThis project hasn't been modified since the last save.";
else
msg += "\nThis project has been modified since the last save.";
msg += "\nProperties: ";
foreach (Property prop in prj.Properties)
{
msg += "\n " + prop.Name;
}
foreach (String s in (Array)prj.Globals.VariableNames)
{
msg2 += "\n " + s;
}
MessageBox.Show(msg, "Project Name: " + prj.Name);
MessageBox.Show(msg2);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
I previously opened 2 other instances of VS, and this gives me the first one, not the none this code is running in.
Anyone know what I'm doing wrong?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Hi,
I need to create a data structure that is very tree like that operates similar to a directory structure. For example:
/ch - will add "ch" to root
/ch/01/config - will add "01" to ch from above and "config" to 01
/ch/02/insert - will add "02" to ch from first line and "insert" to 02
/ch/01/mix/01 - will add "mix" to 01 from second line and "01" to mix
/config/chlink - will add "config" to root and "chlink" to config
which will result in a Tree layout like:
root->ch ->01 ->config
->mix ->01
->02 ->insert
->config->chlink
I have been playing with this for a while now and just can't get anything I write to function in this way. If anyone could point me in the right direction it would be much appreciated!
|
|
|
|
|
DaveyM69 wrote: If anyone could point me in the right direction it would be much appreciated! You'd need a class that can hold a reference to itself (the parent) and a collection of its childeren. Like below;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
class Program
{
public class Folder
{
Collection<Folder> _children;
public Folder Parent { get; private set; }
public string Name { get; set; }
public Collection<Folder> Children { get { return _children; } }
private Folder(Folder parent, string name)
{
_children = new Collection<Folder>();
Parent = parent;
Name = name;
}
public static Folder CreateNewRoot()
{
return new Folder(null, "Root");
}
public Folder CreateFolder(string name)
{
var result = new Folder(this, name);
this.Children.Add(result);
return result;
}
public override string ToString()
{
Folder currentFolder = this;
var pathBuilder = new StringBuilder();
while (currentFolder != null)
{
pathBuilder.Insert(0, currentFolder.Name);
pathBuilder.Insert(0, '/');
currentFolder = currentFolder.Parent;
}
return pathBuilder.ToString();
}
}
static Folder CreatePath(Folder startingFolder, string path)
{
string[] pathParts = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
Folder currentFolder = startingFolder;
for (int i = 0; i < pathParts.Length; i++)
{
string targetName = pathParts[i];
Folder targetFolder = null;
if (0 != currentFolder.Children.Count())
targetFolder = currentFolder.Children.FirstOrDefault(f => f.Name == targetName);
if (null == targetFolder)
{
targetFolder = currentFolder.CreateFolder(targetName);
}
currentFolder = targetFolder;
}
return currentFolder;
}
static void DumpFolderToConsole(Folder fromWhere)
{
Console.WriteLine(fromWhere);
foreach (Folder folder in fromWhere.Children)
{
DumpFolderToConsole(folder);
}
}
static void Main(string[] args)
{
Folder root = Folder.CreateNewRoot();
CreatePath(root, @"/ch");
CreatePath(root, @"/ch/01/config");
CreatePath(root, @"/ch/02/insert");
CreatePath(root, @"/ch/01/mix/01");
CreatePath(root, @"/config/chlink");
DumpFolderToConsole(root);
Console.ReadLine();
}
} Outputs
/Root
/Root/ch
/Root/ch/01
/Root/ch/01/config
/Root/ch/01/mix
/Root/ch/01/mix/01
/Root/ch/02
/Root/ch/02/insert
/Root/config
/Root/config/chlink Some remarks; the example also creates sub-folders if required, even if the starting list was shorter than the resulting dump. It does not contain provisions for other stuff yet, like files. If you want such a structure (complete with a byte[] for the file-class), then there's an example in an article[^] I wrote.
--edit
You asked for a class, not for code; I'd recommend the TreeNode , as it contains a lot what you'd want out of the box. Another advantage thereof would be that it'd be very easy to visualize in a TreeView .
---- edit
PO'H - I unchecked the "Use Markdown formatting" checkbox for you. This fixed the odd layout issues in your code block.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
modified 14-Apr-15 8:47am.
|
|
|
|
|
Thanks Eddy, I'll try this tomorrow
It's actually to hold and look up against OSC[^] addresses for a particular device. I don't need all the wild card stuff thankfully so with what you've given me I should be close.
Thanks again
|
|
|
|
|
You're welcome, and good luck
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I think Eddy V. has given you a great code-example. If you end up needing a very fancy Node structure that keeps track of ancestors, descendants, etc., this is a good resource: [^].
I came across this code for 'Node a few years ago when reading this thread on StackOverflow: [^] which has several code examples for different types of Tree data-structures in C#.
cheers, Bill
«To kill an error's as good a service, sometimes better than, establishing new truth or fact.» Charles Darwin in "Prospero's Precepts"
|
|
|
|
|
For this kind of code sample, I wish I had more than one up-vote
thanks, Bill
«To kill an error's as good a service, sometimes better than, establishing new truth or fact.» Charles Darwin in "Prospero's Precepts"
|
|
|
|
|
Thanks
|
|
|
|
|
Well thanks again Eddy, it's done the job brilliantly with only a few minor tweaks to allow for use in my situation!
Awesome
|
|
|
|
|
You're welcome, and thanks
|
|
|
|
|
You might also want to take a look as SQL Servers HierarchyID[^] structure, I use a string format of that for my NodeKey whenever I have to maintain a tree structure.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
how to do cut copy paste in treeview... and the changes should simultaneously update in xmldocument?
here the treeview has already been populated with xml file
Sandeep Puvvadi
|
|
|
|
|
|
I use C # to insert records into SQL Server 2005 after inserted me into the table to delete records but not receive an error message, you see the image attached, you do know what software debugging SQL Server on http://s17.postimg.org/6wjwqdzcf/error_data.jpg
|
|
|
|
|
Start by showing us the query you used, and the code fragment that used it.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
In other projects I use mongodb gridfs, but there is no driver for windows phone 8.1. I haven't find any database with file store, linq for documents and embedded use availability.
|
|
|
|
|
I don't know if Mehdi Gholam's Raptor Document Store is usable on Win 8.1 phone, but it has been in development here since 2012, and Mehdi is actively supporting it. Worth a look, and, perhaps, a question: [^].
«To kill an error's as good a service, sometimes better than, establishing new truth or fact.» Charles Darwin in "Prospero's Precepts"
|
|
|
|
|
hi, I cant seem to read what's in a file I have created and written text in.
Please help
|
|
|
|
|
Of course that's not normal. But you provided no details, so we have nothing "to work with" and there is no "common cause" for that. If you edit your post and include the relevant parts of your code we might be able to help.
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ReadFromFile
{
class Program
{
static void Main(string[] args)
{
FileStream fs;
StreamWriter fw;
<pre>
fs = new FileStream("D:\\Programming.txt", FileMode.OpenOrCreate, FileAccess.Write);
fw = new StreamWriter(fs);
fw.WriteLine("C# Programming");
fw.WriteLine("C Programming");
fw.WriteLine("C++ Programming");
fs.Close();
}
}
}
|
|
|
|