|
jimmy2shoes wrote: but when i add the media player control in i get the following error
ActiveX control '6bf52a52-394a-11d3-b153-00c04f79faa6' cannot be instantiated because the current thread is not in a single-threaded apartment.
Well, you don't have a choice there. You either set the STA or you don't use the Media Player control.
Why do you have to use MTA?? You can create threads yourself all you want without it...
|
|
|
|
|
hi thanks for getting back to me friend
i have to MTA as i am using the Intel Mobile SDK to monitor Power and Network events and as far as there web site goes i have to use MTA in order for it to function correclty.
i have ran my program with STA and the events do not work
thanks
|
|
|
|
|
In that case, you can try this. You have to keep the Main in your code STA or you lose ActiveX controls. Start a seperate thread, setting its Apartment to MTA before you actually Start the thread. All of your code using this library would have to be running under this thread in order to work (per Intel). I don't know if it'll work, and it might take a large rewrite of your code to find out.
Your best source of information on this problem is actually going to be Intel.
|
|
|
|
|
Yes, things like that can work. We once did such things.
The way I understand it, you can choose the overall MTA/STA status, and then deviate from
it for each new thread you create.
There is one little caveat: for each thread you can set the appartment model only once,
but that should pose no problem.
PS: I don't recall how prefabricated threads (ThreadPool, BackgroundWorker, ...)
behave in this matter.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
trying to write a c# datagridview wrapper class, and i'm having problems setting my form object to the class dgv wrapper.
error: "Cannot implicitly convert type 'System.Windows.Forms.DataGridView' to 'test.Grid'. An explicit conversion exists (are you missing a cast?)"
form code:
breaks on:
"Grid i_grid_o;
i_grid_o = dataGridView3;
i_grid_o.UpdateGrid(i_grid_o);"
wrapper class code:
"using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace test
{
class Grid : DataGridView
{
DataGridView i_grid_o = new DataGridView();
//ctor
public Grid()
{
}
public void UpdateGrid(DataGridView a_grid_o)
{
i_grid_o = a_grid_o;
MessageBox.Show(a_grid_o.ToString());
//DataGridView a_grid_o, a_table_o
//a_grid_o.Update(a_table_o);
}"
anyone can help, will greatly appreciate it!
|
|
|
|
|
Member 3946582,
You just need to do: i_grid_o = (Grid)dataGridView3;
Also, on a side note, you don't need to create a DataGridView in your Grid class. You could change your code to:
private DataGridView _gridView
public Grid(DataGridView dataGridView)
{
_gridView = dataGridView;
}
Then, when ever you want to create a Grid object, just do:
Grid i_grid_o = new Grid(dataGridView3);
i_grid_o.UpdateGrid();
Regards,
Gareth.
modified on Friday, February 15, 2008 1:14 PM
|
|
|
|
|
thanks! That darn casting! You guys are great..
|
|
|
|
|
Hey all,
I have a simple listview question. When a row is clicked, I can get info from a particular column like this:
listView1.FocusedItem.SubItems[0].Text
But how can I get the column dynamically?
Thanks!
PHP and C# Developer for Magezine Publishing Ltd
|
|
|
|
|
I don't have a lot of experience with ListView, but after a quick glance at the API, in your Click method, I think you can use the event args 'e' like:
int colIndex = e.Columns.Index();
I might be wrong though, like I said, never used it much.
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
BenGriffiths wrote: But how can I get the column dynamically?
What does that mean? Get the column they clicked?
led mike
|
|
|
|
|
Yep, i need to get the index of which ever one was clicked
|
|
|
|
|
My suggestion any good? That was what I was assuming.
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
I couldnt figure that way out :s lol, still learning
|
|
|
|
|
First generate the click method: Go into the ListView's events in the form design or if you've coded the ListView:
listView1.ColumnClick += new ColumnEventHandler(listView1_ColumnClicked);
Half way through writing that, Intellisense will say press tab to auto generate method.
Then inside the method, the code I previously wrote should do the job.
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
Ah ok, I think I have figured it out now, thanks
|
|
|
|
|
|
Hi Guy
when u click in the column u can get from the EventArgs.
try like this EventArgs e;
e.Column.Index;
i hope help this
Cheers
RRave
MCTS,MCPD
|
|
|
|
|
I have some problems with reading and writing to an Intranet directory. I always get an permission exception.
The executable file is shared on an NTFS network volume. There is no problem to read and write files directly in executable home directory.
When I try to read/write outside the folder I get an exception.
The next step was to create an PermissionSet but I got an Security Exception.
How I can read/write files
thanks in advance
|
|
|
|
|
|
i'm a beginner in c#. now i'm doing a water model by using bump mapping. i used refer to http://www.riemers.net[^]to do this. the problem is, the code for the bump mapping is in HLSL code. How can i do the code in c#?
[img]http://img488.imageshack.us/img488/6241/signaturesakirahku9.jpg[/img]
|
|
|
|
|
|
You can't, unless you want to write a horribly slow software renderer, which involves a lot more work than learning HLSL/GLSL/Cg (any of those shader languages)+
For more information about graphics programming I suggest you better take a look at those sites:
http://www.gamedev.net[^]
http://forums.xna.com[^]
modified 12-Sep-18 21:01pm.
|
|
|
|
|
thanks for the reply.
[img]http://img488.imageshack.us/img488/6241/signaturesakirahku9.jpg[/img]
|
|
|
|
|
I wrote already some days ago to ask a question: here follows the topic.
"In my application I create some bottons in a form; some of them receive an image to be set as their backgroundImage. When this is done and the mouse hovers on the control I start a timer: I want the program to do something when the -let's say- 5th timer tick occurs, but in the meanwhile I want the image to increase its pixels' alpha value a bit each tick.
How to control the alpha value of an image I load from a file and display it as a backgroundImage on a button?"
KaptinKrunch kindly suggested me a link to have a look to:
http://www.c-sharpcorner.com/UploadFile/mahesh/DrawTransparentImageUsingAB10102005010514AM/DrawTransparentImageUsingAB.aspx
Well, I checked that code, and at some more documentation..and tried that on a small test project, to load a bitmap on a pictureBox, and modify its alpha channel as much as a trackBar in the same form is scrolled, from 0 to 1.
The problem is that: once I have create the Graphics object, loaded with my image, and modified it, I can't reconvert it as a Bitmap object, in such a way to be able to set it as the Image property of the PictureBox of the Form.
Notice this is just a small piece of code to try the thing: actually, in my application, I have to load the bipmap as the BackgroundImage property of a Button, but I don't think this changes a lot..
Thanx for any extra help, sorry for my English..
Here down is listed the code I can't fix:
public partial class Form1 : Form
{
private string sourceFileName;
private string destFileName, proposedDestFile;
private Bitmap image, newImage;
private int modifiedImagesCounter;
ColorMatrix colorMatrix;
ImageAttributes imageAtt;
Graphics g;
public Form1()
{
InitializeComponent();
float[][] matrixItems = {
new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}};
colorMatrix = new ColorMatrix(matrixItems);
imageAtt = new ImageAttributes();
imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
}
private void loadImageButton_Click(object sender, EventArgs e)
{
openFileDialog.ShowDialog(Parent);
sourceFileName = openFileDialog.FileName;
image = new Bitmap(sourceFileName);
Console.WriteLine("The file to modify is: " + sourceFileName);
//IndexedToARGB_Converter conv = new IndexedToARGB_Converter(sourceFile);
//Bitmap modifiedImage = conv.getNewImage();
pictureBox.Image = image;
}
private void saveImageButton_Click(object sender, EventArgs e)
{
proposedDestFile = DestFileName();
saveFileDialog.FileName = proposedDestFile;
saveFileDialog.ShowDialog(Parent);
destFileName = saveFileDialog.FileName;
Console.WriteLine("The modified file will be saved to: " + destFileName);
newImage.Save(destFileName);
}
private string DestFileName()
{
modifiedImagesCounter++;
StringBuilder strbld = new StringBuilder();
strbld.Append(sourceFileName, 0, sourceFileName.Length - 4);
strbld.Append(modifiedImagesCounter.ToString());
strbld.Append(".GIF");
return strbld.ToString();
}
private void trackBar_Scroll(object sender, EventArgs e)
{
g = pictureBox.CreateGraphics();
//Graphics g = Graphics.FromImage(image);
TrackBar trackBar = (TrackBar)sender;
float f = (float)(trackBar.Maximum - trackBar.Value) / (float)(trackBar.Maximum - trackBar.Minimum);
colorMatrix[3, 3] = f;
int iWidth = image.Width;
int iHeight = image.Height;
Rectangle rect = new Rectangle(pictureBox.Location.X, pictureBox.Location.Y, iWidth, iHeight);
g.DrawImage(
image,
rect, // destination rectangle
0.0f, // source rectangle x
0.0f, // source rectangle y
iWidth, // source rectangle width
iHeight, // source rectangle height
GraphicsUnit.Pixel,
imageAtt);
this.Update();
}
}
|
|
|
|
|
Here is a little method that I think will do what you desire. It requires unsafe code, but will probably be extremely fast:
private static Bitmap ChangeImageAlpha(Bitmap bmp, float newAlpha) {
Bitmap rval = new Bitmap(bmp);
BitmapData bmpData = rval.LockBits(new Rectangle(0, 0, rval.Width, rval
.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
try {
unsafe {
byte* bmpPtr = (byte*)bmpData.Scan0.ToPointer();
byte* last = bmpPtr + (bmp.Height * bmp.Width << 2);
do {
float a = (*bmpPtr) * newAlpha;
*bmpPtr = (byte)Math.Max(Math.Min(a, byte.MaxValue), byte.MinValue);
bmpPtr += 4;
} while (bmpPtr < last);
}
return rval;
} catch {
return null;
} finally {
bmp.UnlockBits(bmpData);
}
} I have not tested this code, so I don't know if it actually works or not. Things to check:
1: The constructor used to create rval actually copies the image data
2: The alpha channel is the first byte in each double-word (if not, change all *bmpPtr to bmpPtr[3])
Hope this helps,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|