|
|
Hi Luc,
I think you and the OP are miscommunicating. Let me see if I can help to clear things up. Say you want to display a PDF in a WebBrowser control. You'd have to 1) have some HTML that makes uses of <embed> to point to a PDF and 2) have that embed tag point to some location that is storing the PDF. Now, if the application making use of the WebBrowser is entirely local, it would be impossible to, say, serve up a PDF file when a certain URL is hit (that would solve the problem of using a stream to serve a PDF, but only if the OP has access to a web server). Now, if the user wants to do everything on the client side without any file access or remote URL access, then it seems there may be a problem displaying the PDF. The OP is claiming that images can be directly displayed by a WebBrowser control (i.e., by passing the memory stream to the WebBrowser) but that the WebBrowser is incapable of displaying a PDF, except for via an <embed> tag. If you use the EMBED approach, you have to point to somewhere, and that somewhere can't be a memory stream.
By the way, the tip/trick you made doesn't work for me. I just see an "X" displayed where there should be an image. Not sure why that is. Perhaps the type of data needs to be specified somehow (usually this would be provided by the server in the HTTP header, but there is no HTTP header AFAIK when you set the WebBrowser control to use a memory stream).
|
|
|
|
|
Thanks for your effort, however it did not change my view on things, so maybe I misunderstood both of you now, or, well, I don't know. I'll try to summarize the main facts so far:
1.
I understood the OP wants to see local data (images, PDF, whatever) which is stored in a database rather than in individual files, and wants to avoid the use of temporary files. I take it all he wants to see is one data object at a time, not a composition of some HTML and one or more database data objects. I am assuming all data types are popular types known to web browsers. If not, special viewers would be required (e.g. a HEX viewer for unstructured, "meaningless", binary data.
2.
The Tip&Trick works fine on my system, which has Vista-32, IE7 as original browser, FF3 as default browser, and using a .NET 2.0 debug build. So I would be inclined to say images cause no fundamental problem, provided they use a format WebBrowser recognizes AND understands (such as GIF).
3.
I have no idea yet what could go wrong for you there. I tested the exact code as published inside a pre-existing WinForm application. So I have some questions for you:
(A) did you change the code at all?
(B) what are your system's characteristics?
(C) Knowing the WebBrowser's size is 500*500, how large is the "X"? I assume it is red?
4.
If the OP uses my T&T code and replaces my synthetic image by some data read from his database, images should work.
5.
Hristo Bojilov signaled PDF would not work that way, and indeed PDF seems more complicated; IE and FF successfully load and display a remote PDF (when typing an URL in the address bar), WebBrowser also successfully navigates to the same PDF file, but fails to recognize a PDF when simply feeding it in its DocumentStream. It then simply shows the bytes as text. Some research has led to two complex ways around it, one of them is an article here on CP; the basic idea is to help WebBrowser in recognizing PDF files and selecting the right way to handle them, and so it is not based on an EMBED or OBJECT tag, as they would require a file. I haven't tested these yet, I have more urgent matters right now.
6. "but only if the OP has access to a web server"
I once created an embedded web server; it basically is a class one adds to an existing project; it takes data and produces web pages (that part of course needs customization), available on localhost at some port number. Doing so enables any WinApp to make data available to a browser running on the same PC, possibly a WebBrowser within the same app. As it basically uses WebRequest/WebResponse classes, it can provide data as well as data type information, so that should suffice to deliver all popular data formats without requiring files. It is pretty complex though (ca.300 LOC), way too large for a Tip&Trick. I would have to test it again for images and PDFs, but it looks like one way to get it all solved.
7.
I also once did some PDF server/client work a few years back, alas all in PHP and based on a couple of PHP libraries, which means impossible to port in a jiffy. I'd rather not go that route.
Conclusion:
- it is work in progress
- please correct me if you disagree with any of the above
- and please provide answers to the questions in (3), about the T&T not working for you.
Cheers.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
I need to save the selected row and the vertical scrollBar's position after a refresh. This is how I do it:
int currRow = myGrid.CurrentRowIndex;
int vScrollPos = ((ScrollBar)myGrid.Controls[1]).Value
myGrid.CurrentRowIndex = currRow;
myGrid.Select(currRow);
((ScrollBar)myGrid.Controls[1]).Value = vScrollPos;
Here's my problem: The grid always jumps to a place where the selected row is at the bottom. 'Select' does exactly that (similar to EnsureVisible of newer grid implementations). But after that there's the vScrollBar repositioning - and it just does nothing. In debug I see the scroll bar value gets updated. In the UI, if I hit the down/up arrow the scrollbar suddenly jumps to where it should have been according to it's updated property - But if I don't click anything the grid is just in the wrong position. I tried refreshing the grid/scroll bar to force a redraw, but it doesn't help. This is really frustrating, as the code is right there and it just doesn't comply
Thanks for your help.
|
|
|
|
|
I am creating an installer where i need to install SQL server express.
i am doing this with help of a bat file. But i am getting an error, saying that..
One installer is running so i can't run another one.
My Question is. How can i install sqlserver express at the time of installation of Application.
Thank you
|
|
|
|
|
Hi,
Let's say there are 3 objects:
Class A
Class B : A
Class C : B
I want to pass through all objects that derive from Type B
C obj1 = new C();
B obj2 = new B();
if(obj1.GetType() == typeof(B)) {
//--Pass through all objects that derive from object B or object A...
}
typeof comapares directly the top types C must equal C... No polymorphic comarison...
How to do a polymorphic comparison? Which keyword or mechanism to use?
Thanks!
|
|
|
|
|
if(obj1 is B) should work for you
|
|
|
|
|
|
As lukasz_nowakowski says, is is what you want. The alternative is as
if (obj is B)
{
B bInstance = (B) obj;
...
} or
B bInstance = obj as B;
if (bInstance != null)
{
...
} You can use either, I prefer the second as I prefer explicit null tests. That's just personal preference though.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
If you want to just add it to objects' list, then is is enough, but if you want to use object obj as instance of class B, then B instance = obj as B; is the path to follow. To find out why read for example this[^].
|
|
|
|
|
The work with polymorphic objects after comparison is very clear to me.
I just didn't know how to compare them in C#...
Thanks!
|
|
|
|
|
FYI - while the use of is and as are what's appropriate for your problem, as lukasz_nowakowski and OriginalGriff have said, your example code used GetType ... which put me in mind of how to do a similar test on Types, rather than objects:
Type typeOfC = typeof(C);
Type typeofSomeObject = someObject.GetType();
if (typeOfC.IsAssignableFrom(typeofSomeObject))
{
}
|
|
|
|
|
Hello everybody!!!
we have a problem with crystal reports and c#.
we would like to pass the data to the report directly with parameters, but we don't know how to add the pages in the report.
this is the code we have. we pass the parameters to the report witin a forreach, but we just get a report with only one page and with values of the last row of the dataset in the report.
Any idea please???
try
{
SqlDataAdapter daCategory = new SqlDataAdapter();
daCategory.SelectCommand = new SqlCommand();
daCategory.SelectCommand.CommandType = CommandType.StoredProcedure;
daCategory.SelectCommand.Connection = kon.SqlConn;
daCategory.SelectCommand.CommandText = "asp_admin._DatosReport";
SqlParameter parameter = daCategory.SelectCommand.Parameters.Add("@numero", SqlDbType.Int);
parameter.Value = instalazioa;
parameter = daCategory.SelectCommand.Parameters.Add("@Fecha", SqlDbType.DateTime);
parameter.Value = Convert.ToDateTime(FechaElegida);
DataSet ds = new DataSet();
daCategory.Fill(ds, "Termico");
if (ds.Tables["Termico"].Rows.Count > 0)
{
ParameterValues CurrentParameterValues = new ParameterValues();
foreach (DataRow rw in ds.Tables["Termico"].Rows)
{
NInst = new ParameterDiscreteValue();
Rep = new ParameterDiscreteValue();
Dev = new ParameterDiscreteValue();
datosActuales.NInstalacion = Convert.ToInt32(rw["NInstalacion"]);
datosActuales.NRepetidor = Convert.ToInt32(rw["NRepetidor"]);
datosActuales.NDevice = Convert.ToInt32(rw["NDevice"]);
//meter los valores de las variables
NInst.Value = datosActuales.NInstalacion;
//reporte.SetParameterValue("Instalacion", NInst);
Rep.Value = datosActuales.NRepetidor;
//reporte.SetParameterValue("Rep", Rep);
Dev.Value = datosActuales.NDevice;
// reporte.SetParameterValue("Dev", Dev);
CurrentParameterValues.Add(NInst);
CurrentParameterValues.Add(Rep);
CurrentParameterValues.Add(Dev);
}
}
}
finally
{
kon.closeConexion();
}
//se crea el report en pdf
reporte.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Termico");
}
|
|
|
|
|
|
I have stumbled on some bug with IntelliSense in Visual Studio 2005.
The bug/problem is that IntelliSense don't display the drop-down-list for a class instance returned by a method.
Here is a sample code (Don't mind the compile error in the Main()-method, we will get to it):
class Program
{
static List<Car> carList = new List<Car>();
static Cars cars;
static void Main(string[] args)
{
carList.Add(new Car("Black", "Volvo"));
carList.Add(new Car("Blue", "Volvo"));
carList.Add(new Car("Black", "Audi"));
cars = new Cars(carList);
string c = cars["Volvo"]
foreach (Car car in cars["Volvo", "Blue"])
Console.WriteLine(car.Color + " : "+ car.Model);
}
}
class Cars
{
List<Car> carList;
public Cars(List<Car> carList)
{
this.carList = carList;
}
public Car this[string model]
{
get
{
foreach (Car car in carList)
{
if (car.Model == model)
return car;
}
return null;
}
}
public List<Car> this[string model, string color]
{
get
{
List<Car> cars = new List<Car>();
foreach (Car car in cars)
{
if (car.Model == model && car.Color == color)
cars.Add(car);
}
return cars;
}
}
}
class Car
{
string color;
string model;
public Car(string color, string model)
{
this.color = color;
this.model = model;
}
public string Color
{
get { return color; }
set { color = value; }
}
public string Model
{
get { return model; }
set { model = value; }
}
}
Notice the cars["Volvo"] in the Main()-method which returns a Car-type instance. I want to pass the Color property to the string c variable.
When I want the drop-down-list to show the properties of the Car instance cars["Volvo"]. it's gone.
I can still pass the car instance's Color property to the string c variable but I have to manually type: .Color; .
I dug in this a bit deeper and found out if you comment out:
public List<Car> this[string model, string color] property in the Cars class,
the IntelliSense is back working and the cars["Volvo"]. displays the drop-down-list.
I made a new property in the Cars class.
The public List<Car> this[string model, string color] was still commented out.
public List<Car> this[int amounth]
{
get
{
List<Car> list = new List<Car>();
for (int i = 0; i < amounth; i++)
list.Add(carList[i]);
return list;
}
}
Same result in the Main() method.
I guess this is a bug in the IntelliSense. Can I fix this in some way?
/Steffe!
|
|
|
|
|
You can buy a 3rd party intellisense tool. The only one I know of is Visual Assist by Whole Tomato Software[^]. That's the only way to fix Intellisense in Visual Studio.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
|
ReSharper can also replace Visual Studio's intellisense (at least I think it does...it may just "enhance" its functionality).
The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen
|
|
|
|
|
Hello,
I developed a windows application on VS2010 using .net framework 4
How can i convert it to .net framework 3?
|
|
|
|
|
Have a look here[^].
My signature "sucks" today
|
|
|
|
|
If you are using any of the features that were introduced in .NET 4 (e.g. SortedSet), then you need to convert that portion of the code.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I've got a central SQL server database. My solution has a WCF service responsible for synchronizing data with clients running SQL Server or SQL Server Express.
The service uses Microsoft Sync Framework and it works well, but the Sync Framework requires a direct connection to my client's server, and clients that are running SQL Server Express may not have a static IP address to let my application locate them.
How can I overcome this problem? Does Sync Framework have an intermediate service that can exchange datasets of changes on both server and client? Or can I use Sync Framework to get datasets of changes?
Dad
|
|
|
|
|
for example, server chars in the image.
How to get the char?
|
|
|
|
|
After spending around 1 hour I finally found who's causing the problem. And it was TextureBrush which has something wrong, maybe not ?
Check this image
http://tinypic.com/r/2uzrrqx/6[^]
I want to draw tiles of it on a big image but on specific region, so to do that...I wrote the following code(for testing only)
Bitmap b = new Bitmap(512, 300);
Graphics g = Graphics.FromImage(b);
TextureBrush tb = new TextureBrush(Image.FromFile(@"C:\dsfsdf.png"));
g.FillRectangle(tb, 80, 0, 512 - 80, 300);
tb.Dispose();
g.Dispose();
pictureBox1.Image = b;
result is
http://tinypic.com/r/mifb5h/6[^]
now the problem is, TB is drawing from (0, 0) offset and trimming the outer part of rectangle. But it should draw from (80, 0). I know I can do that by changing its offset(tb.TranslateTransform(80, 0)) but why this is happening in first place. That suppose to be default.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
I'm not convinced anything is wrong (except for a anisotropic scale factor)
I expect a TextureBrush to repeat the input image (like rolls of wallpaper), with a fixed phase, i.e. the texture gets anchored to the origin of the destination, so separate pieces would stay "in phase".
what is causing the solid pink color?
check your PictureBox sizemode.
best is to (temporarily) set PictureBox SizeMode to AutoSize, to convince yourself the image is right (or wrong)
well, actually best is not to use a PictureBox at all, they seem to always confuse people.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|