I am getting an error when trying to embed a flash (.swf) file into my Visual C' form - I have notice this is a fairly common error, though the solutions don't mean much to me.
Here is my code:
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;
using AxShockwaveFlashObjects;
using ShockwaveFlashObjects;
namespace WindowsFormsApplication1
{
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 frm1 = new Form1();
frm1.ShowDialog();
}
private void axShockwaveFlash2_Enter(object sender, EventArgs e)
{
**//this.axShockwaveFlash1.LoadMovie(0, "C:\\Documents and Settings\\Gary\\My Documents\\Flash File\\CalmBay1.swf");**
}
private void Form6_Load(object sender, EventArgs e)
{
AxShockwaveFlash axShockwaveFlash = new AxShockwaveFlash();
axShockwaveFlash.Location = new System.Drawing.Point(50, 50);
this.Controls.Add(axShockwaveFlash);
**axShockwaveFlash.Movie = ("C:\\Documents and Settings\\Gary\\My Documents\\Flash File\\CalmBay1.swf");**
//ShockwaveFlash.Size = new System.Drawing.Size(150, 150);// set size as required
axShockwaveFlash.Play();
}
}
}
The line with the asterix is where the error is, but as i say, i've no idea on how to resolve it!
Even though it's been months since this question was asked, I just had the same problem. When creating AxShockwaveFlash objects programmatically, you have to initialize:
var flashObj = new AxShockwaveFlash();
((ISupportInitialize) (flashObj)).BeginInit(); // <--
flashObj.Dock = DockStyle.Fill;
flashObj.Enabled = true;
((ISupportInitialize) (flashObj)).EndInit(); // <--
Controls.Add(flashObj);
flashObj.AutoSize = true; // All of these properties won't work unless the component has been initialized
flashObj.ScaleMode = 1;
flashObj.AlignMode = 0;
flashObj.LoadMovie(0, #"movie.swf");
flashObj.Stop();
flashObj.Play();
Hopefully this will save future readers some time.
I had the same problem I tried the proposed solutions of calling CreateControl without any success.
It turned out that the interops were generated targeting the .net 2.0 framework and the problem occurred when being called from 4.0 code. The solution was to generate interops using .NET Framework Tools 4.0.
Related
I'm aware this question has been asked already - but none provided a resolution.
I have read these links:
Xamarin Forum, Stack Overflow Q and some others.
I have a relatively simple project at the moment and I keep getting the error "The name 'Resource' does not exist in the current context"
I can restart the project & it will work and "resource" is underlined in red and I can still debug the project.
Then after a few tries it goes and complains that it's not in the current context.
I did not make any changes to the project - I have come back to it now from a while ago.
So I'm going to guess that updates to VS 2015 have broken it.
My Code example:
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Views.InputMethods;
using Android.Graphics.Drawables;
using Android.Graphics;
namespace Designer
{
[Activity(Label = "Designer", MainLauncher = true)]
public class MainActivity : Activity
{
// Global Varialble
Button butSignIn;
EditText tbxUsername;
TextView txtErrorMsg;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
butSignIn = FindViewById<Button>(Resource.Id.butSignIn);
butSignIn.Click += ButSignIn_Click;
tbxUsername = FindViewById<EditText>(Resource.Id.txtUsername);
txtErrorMsg = FindViewById<TextView>(Resource.Id.txtErrorMessage);
ActionBar.SetDisplayShowTitleEnabled(false);
ColorDrawable colorDrawable = new ColorDrawable(Color.ParseColor("#ff70bc1e"));
ActionBar.SetBackgroundDrawable(colorDrawable);
}
private void ButSignIn_Click(object sender, System.EventArgs e)
{
if (tbxUsername.Text == "Azmodan")
{
Intent intent = new Intent(this, typeof(MenuActivity));
this.StartActivity(intent);
this.Finish(); // this will close the activity and will close app if we try go back
}
else
{
txtErrorMsg.Visibility = ViewStates.Visible;
txtErrorMsg.Text = "inccorect login details, please try again";
}
}
}
}
Any help would be appreciated.
I have a Xamarin Forms solution. I added sqlite-net-pcl as reference to all projects. It works fine on Android but crashes on Windows 8.1 and Windows Phone 8.1. I have an IOS project but I don't have OSX at the moment to try it.
I use this in the Windows projects to access the database:
using System.IO;
using SQLite;
using Xamarin.Forms;
using HelloXamarin.Windows;
using Windows.Storage;
[assembly: Dependency(typeof(SQLiteDb))]
namespace HelloXamarin.Windows
{
public class SQLiteDb : ISQLiteDb
{
public SQLiteAsyncConnection GetConnection(string databaseName)
{
var documentsPath = ApplicationData.Current.LocalFolder.Path;
var path = Path.Combine(documentsPath, databaseName);
return new SQLiteAsyncConnection(path);
}
}
}
Here are my references:
I get this exception when trying to access the database:
The type initializer for 'SQLite.SQLiteConnection' threw an exception.
Unable to load DLL 'e_sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at SQLitePCL.SQLite3Provider_e_sqlite3.NativeMethods.sqlite3_win32_set_directory(UInt32 directoryType, String directoryPath)
at SQLitePCL.SQLite3Provider_e_sqlite3..ctor()
at SQLitePCL.Batteries_V2.Init() at SQLite.SQLiteConnection..cctor()
I have no idea how to solve this, please help me!
The whole solution is available on GitHub:
https://github.com/apspot/HelloXamarin
For me, it worked by adding the e_sqlite3 bundle to the executable project
By this time the issue is still open. So before they come with some solid fix, you can use this work around, to solve the issue for now.
Add one helper class
using System;
using System.Diagnostics;
using System.IO;
namespace SQLitePCL
{
public class NativeLibraryHack
{
public static bool Hacked { get; private set; }
public static bool DoHack()
{
if (Hacked) return true;
try
{
const string runtimeFolderName = "/runtimes";
var destinationPath = typeof(SQLitePCL.raw).Assembly.Location
.Replace("\\", "/");
var destinationLength = destinationPath.LastIndexOf("/", StringComparison.OrdinalIgnoreCase);
var destinationDirectory = destinationPath.Substring(0, destinationLength) + runtimeFolderName;
var sourcePath = new Uri(typeof(SQLitePCL.raw).Assembly.CodeBase)
.AbsolutePath;
var sourceLength = sourcePath.LastIndexOf("/", StringComparison.OrdinalIgnoreCase);
var sourceDirectory = sourcePath.Substring(0, sourceLength) + runtimeFolderName;
if (Directory.Exists(sourceDirectory))
CopyFilesRecursively(new DirectoryInfo(sourceDirectory), new DirectoryInfo(destinationDirectory));
}
catch (Exception ex)
{
//Ignore Exception
Debug.WriteLine(ex.Message);
return false;
}
return (Hacked = true);
}
private static void CopyFilesRecursively(
DirectoryInfo source,
DirectoryInfo target
)
{
foreach (var dir in source.GetDirectories())
CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name));
foreach (var file in source.GetFiles())
{
try
{
var destinationFile = Path.Combine(target.FullName, file.Name);
if (!File.Exists(destinationFile))
file.CopyTo(destinationFile);
}
catch (Exception ex)
{
//Ignore Exception
Debug.WriteLine(ex.Message);
}
}
}
}
}
And add the hack before your db migration script, I am using web api 2
so i did on RouteConfig.RegisterRoutes
NativeLibraryHack.DoHack();
using (KSDBContext db = new KSDBContext())
{
db.Database.Migrate();
}
You need to add the SQLite Extensions.
Go to Tools > Extensions and Updates
Go to Online, then search for SQLite.
Download SQLite for Windows Runtime
In your Windows Project, Add Reference and ensure you add the extension.
Also remove Microsoft.VCLibs from your references.
Try referencing Visual C++ 2015 Runtime for Universal Windows Platform Apps. That sorted it out for me.
Go to References
Add Reference
Extensions.
Check"Visual C++ 2015 Runtime for Universal Windows Platform Apps"
OK
I am making a simple app that sends location data to a server using http get request.
The problem is that the request is made only on the first time despite the fact that it is inside the positionchanged event handler.
Here is my code. I can't find what is wrong with it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Device.Location;
namespace kechap
{
public partial class MainPage : PhoneApplicationPage
{
GeoCoordinateWatcher gw = new GeoCoordinateWatcher();
Uri url = new Uri("http://127.0.0.1:5000/upload/1e3fae069dd62fa1641183cd77092ed2053a0e75/1/2");
// Constructor
public MainPage()
{
InitializeComponent();
gw.MovementThreshold = 10;
gw.PositionChanged += (s, e) =>
{
MyMap.Center = e.Position.Location;
MyPushpin.Location = e.Position.Location;
WebClient wc = new WebClient();
wc.OpenReadAsync(url);
wc.OpenReadCompleted += (ss, ee) =>
{
};
};
gw.Start();
}
}
}
At a guess I would say the URI, which in the code you have posted does not change between calls, is resolved from cache after the first time. I suggest you use the age old hack of appending a parameter and giving it a value that changes with each invocation (eg the position you seem to want to report).
I used visual2010 to write a simple app with httpWebRequest class. The very first time of running the app, it'd work but after some successes, it was stuck with warning
"unable to connect the remote server".
I have read a lot in net but not much clues could done, almost said because the anti virus soft or firewall cause the problem, but when i'd turn off both, it still does not work. I also reinstall visual2010 but the problem still
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
namespace new_httpWebRequest
{
class Program
{
static void Main(string[] args)
{
string result ="";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://my-favor.net");
// line code problem below:
`HttpWebResponse response = (HttpWebResponse)request.GetResponse();`
var sr = new StreamReader(response.GetResponseStream() ?? System.IO.Stream.Null, Encoding.UTF8);
result = sr.ReadToEnd();
sr.Close();
Console.Write(result);
Console.ReadLine();
}
}
}
finally, i find the solution just by adding this line:
request.Proxy = null;
I don't know why it work, just do it by god bless.
This might seem like an odd question, but I need to turn my code into a pdf - so I can hand it in. Yes sadly the school system demands the code on cd as a pdf. What I could do is open every class in my solution and copy paste it. But - as a programmer - I am lazy and would like to know if Visual Studio has any feature for this? or if there is any other way?
Edit: A third party program that iterates through all files in a folder, opens the file and copies it's content, into a pdf file. Would do aswell - it does not have to be within Visual Studio.
Got tired of waiting, here's what I came up with:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace GetFileContents
{
class Program
{
static string types = ".js,.cshtml,.cs,.less,.css";
private static string text = "";
static void Main(string[] args)
{
//This folder wraps the whole thing.
string folderPath = #"C:\randomFolderWhereProjectIs\";
string s = IterateIt(Directory.GetDirectories(folderPath).ToList());
//Save to file or whatever I just used the text visualiser in Visual Studio
}
private static string IterateIt(List<string> l)
{
foreach (var path in l)
{
var files = Directory.GetFiles(path).Select(c => new FileInfo(c)).Where(c => types.Split(',').Contains(c.Extension));
foreach (var fileInfo in files)
{
text += fileInfo.Name + "\r\n";
using (StreamReader reader = fileInfo.OpenText())
{
text += reader.ReadToEnd() + "\r\n";
}
}
text = IterateIt(Directory.GetDirectories(path).ToList());
}
return text;
}
}
}