|
Seems like you are doing something wrong then.
Here[^] is an article that should help you out.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Not sure what you're doing wrong - but plainly something!
This test code works and adds "mathematics" to the ListView twice, once from the UI thread and once from another thread by calling Invoke on the ListView :
using System.Threading;
using System.Windows.Forms;
public delegate void AddSubjectDelegate(ListViewItem item);
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
StartAddItem();
new ThreadStart(StartThread).BeginInvoke(null, null);
}
private void StartThread()
{
StartAddItem();
}
private void StartAddItem()
{
ListViewItem listItem = new ListViewItem("mathematics");
AddSubjectDelegate addSubject = new AddSubjectDelegate(AddListItem);
if (lvSubjects.InvokeRequired)
{
lvSubjects.Invoke(addSubject, listItem);
}
else
addSubject(listItem);
}
private void AddListItem(ListViewItem item)
{
lvSubjects.Items.Add(item);
}
}
|
|
|
|
|
Hi everyone, I'm working in VS2010 and trying to create an app that interacts with Excel. I've added The MS Excel 14.0 Object Library reference (COM Tab) and at the top of my code I have the following:
using Microsoft.Office.Interop;
using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Word;
I've tried to do:
var x1 = new Excel.Application();
and I get the error. My project is .Net framework 4. I've tried to find an answer on Google and did what was suggested on a few other forums but still this is not working for me anyone any ideas why?
|
|
|
|
|
pmcm wrote: var x1 = new Excel.Application();
try: var x1 = new Microsoft.Office.Interop.Excel.Application();
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
your suggestion worked but instead of doing that every time throughout my code I've set this up:
using Excel = Microsoft.Office.Interop.Excel;
any idea why my project doesn't seem to be picking up the references that I added?
Thanks
|
|
|
|
|
This is the correct way to do it, as described here[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
That doesn't work in .NET 2.0+, since you can't prefix a class name with a "part" of the namespace like that.
Bastard Programmer from Hell
|
|
|
|
|
OP is using .NET 4.0.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Shouldn't work in 4.0 either, but I'm too lazy to give it a try right now
Bastard Programmer from Hell
|
|
|
|
|
Eddy Vluggen wrote: Shouldn't work in 4.0 either
I've used it in 3.0 and it worked fine. Did you read the linked article I referred to?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
That tells us that you have probably used VB to implement the example, as C# doesn't allow a prefix of the classname with a partial namespace;
Namespace Mine.Test
Public Class SomeClass
Public Property P As Guid
End Class
End Namespace
--
Imports ScratchVb.Mine
Module Module1
Sub Main()
Dim X As Object = New Test.SomeClass()
End Sub
End Module
using System;
namespace Mine.Test
{
class SomeClass
{
public Guid P { get; set; }
}
}
--
using Mine;
namespace Scratch
{
class Program
{
static void Main(string[] args)
{
Object X = new Test.SomeClass();
Object X = new Mine.Test.SomeClass();
}
}
}
Yes, read the article some time ago. Did you try it?
Bastard Programmer from Hell
|
|
|
|
|
Eddy Vluggen wrote: That tells us that you have probably used VB to implement the example, as C# doesn't allow a prefix of the classname with a partial namespace;
Wrong on both counts.
Eddy Vluggen wrote: Yes, read the article some time ago. Did you try it?
Yes I tried it, using C# as i)I never use or have used VB/VB.NET and ii)the title of the article is How to automate Microsoft Excel from Microsoft Visual C#.NET!
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Richard MacCutchan wrote: Yes I tried it, using C#
Never mind
Bastard Programmer from Hell
|
|
|
|
|
Eddy Vluggen wrote: Never mind
I don't mind, it's you that kept banging on about it, like a
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
when you do
using some1.some2.some3;
then the C# compiler will add "some1.some2.some3" to the list of known prefixes, which it uses to locate a type.
Therefore,
using System.Windows.Forms;
...
Form f=new Form();
Forms.Form f2=f;
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
i think you should use "Add reference",
right click on form->Add reference,
there you will get all the namespace which are available.
|
|
|
|
|
I've added the MS Excel 14.0 Object Library reference (COM Tab), Richard the link that you have recommended is one that I have already followed but I was still getting the error.
|
|
|
|
|
pmcm wrote: Richard the link that you have recommended is one that I have already followed but I was still getting the error.
Can you show your code and the exact text of the error message?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I fixed this issue by doing:
using Microsoft.Office.Interop;
using Excel = Microsoft.Office.Interop.Excel;
using Word = Microsoft.Office.Interop.Word;
|
|
|
|
|
That's what I suggested yesterday.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hi.
I write a code for create a polygan in c#
Now i want moving it on the form but i cant.
I want know how i can move a polygan on the form.
My code for create a polygan is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace graphic_aghaye_bagheri
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class polygan
{
public int x1;
public int y1;
public int x2;
public int y2;
public int x3;
public int y3;
public int x4;
public int y4;
public int x5;
public int y5;
public polygan(int x11, int y11,int x22,int y22,int x33,int y33,int x44,int y44,int x55,int y55)
{
x1 = x11;
y1 = y11;
x2 = x22;
y2 = y22;
x3 = x33;
y3 = y33;
x4 = x44;
y4 = y44;
x5 = x55;
y5 = y55;
}
}
private Graphics x;
private Pen myPen = new Pen(Color.Tomato,5);
int r = 30;
int currentvert = 5;
private polygan polygan1 = new polygan(200,200,300,200,350,250,300,300,200,300);
private void button1_Click(object sender, EventArgs e)
{
Point[] myPoints = { new Point(200, 200), new Point(300, 200), new Point(350, 250), new Point(300, 300), new Point(200, 300) };
Graphics myG = this.CreateGraphics();
Pen myPen =new Pen(Color.Tomato, 4f);
x.DrawPolygon(myPen, myPoints);
timer1.Start();
}
private void Form1_Load(object sender, EventArgs e)
{
x = this.CreateGraphics();
}
private void timer1_Tick(object sender, EventArgs e)
{
polygan1.x1 = polygan1.x1 + r;
polygan1.y1 = polygan1.y1 + r;
polygan1.x2 = polygan1.x2 + r;
polygan1.y2 = polygan1.y2 + r;
polygan1.x3 = polygan1.x3 + r;
polygan1.y3 = polygan1.y3 + r;
polygan1.x4 = polygan1.x4 + r;
polygan1.y4 = polygan1.y4 + r;
polygan1.x5 = polygan1.x5 + r;
polygan1.y5 = polygan1.y5 + r;
}
}
}
Tanks a lot.
|
|
|
|
|
Just updating the points in your timer won't actually redraw your polygon. You actually need to trigger a paint message to redraw the polygon (the crudest method being to refresh the form). You really need to move the paint functionality into the form Paint event handler so you can just get the Graphics object there rather than creating your own (which you haven't disposed).
The other big problem is that you create your polygon and then you don't use it to draw with. I would fix that if I were you.
|
|
|
|
|
You may want to read this article[^], it explains the principles you need.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Copy this code after creating a new form (without copying form references).
You need to copy namespaces as well.
Run it and see what issues you get - you can post them here and someone may help you.
|
|
|
|
|
Abhinav S wrote: Copy this code Are you referring to the code in the link posted by Luc ? ... or ... missing link ?
thanks, Bill
"The first principle is that you must not fool yourself, and you are the easiest person to fool." Richard Feynman
|
|
|
|